We are developing a network application based on C/S, in this application the server needs to transfer files to clients and sometimes receive files from clients. So in the server application, for every client it needs to create a control socket and many transfer sockets.
My question is how we can create and define a socket as role of control socket or transfer socket? ( below are deleted: And how can the server application distinguish between the control socket and the transfer sockets? ). Currently the servers use a listening socket, and for all new connections established by accept(listening socket), it stores them equally in an array, finally lets the client register them to the server as control sockets or transfer sockets(means before transferring a file, the client needs to tell which socket it wants to use as control socket and which sockets it want to use as transfer sockets).
I don’t think this is a good patter for creating control sockets and transfer sockets between server application and the clients. So is there any other patters that is suitable for this kind of problems?
Same way you create any other socket. I don’t understand the question.
By being told by the client, and remembering it in some sort of data structure per client. Or maybe you should use different listening ports for control sockets and transfer sockets. Or maybe the transfer socket should be a callback as in FTP.