Reputation: 646
I am developing a client-server program in C. Server supports multiple connections from the same port and creates a new process for each connected client. Client is able to send several commands to the server and get results from there. One of these commands is 'get' which is for transferring any files from server to client. (Such as, get abc.txt bcd.pdf ...).
However this transfer operation should be done in different thread(s). For example, if client requests to transfer 3 files from the server; 3 different threads are created on both server and client side. So that, client will create client_thread1, client_thread2, client_thread3 and server will create server_thread1, server_thread2, server_thread3 for the files. And then first file will be uploaded by server_thread1 to client_thread1, second file will be uploaded by server_thread2 to client_thread2 and so on.
That was the only point I stuck. How can I match a server thread with a client thread; so that server thread only communicates with client thread while server and client side is doing their own job freely.
Thanks for your help.
Upvotes: 0
Views: 267
Reputation: 4671
If you want independent progress between the file transfers, then you'd have to open multiple connections to your server. So you'd have a separate socket for the command channel, and a socket for each concurrent file transfer. You can then service each socket either from a separate thread (bad, as mentioned above), or using something like poll
to multiplex socket processing on one thread. And just like that, you rewrote FTP :)
Alternatively, you could come up with some scheme to multiplex several file transfers on one socket.
Upvotes: 2