tags:

views:

63

answers:

2

Hi,I can not get why it uses two different socket please help me thanks.

The client would request a file through socket 9123 from the server, the server would then send the file to the client through socket 8123 on which every client would be listening once it requests a file.

A: 

TCP connections are between two port numbers. The client has a port number for the reply to be delivered to, and the server has a port for the client to send the request to.

Will
+1  A: 

You need to explain it better than that...

  • does each client listen on UDP port 8123 and the server is supposed to communicate with all at once - if so, that's a UDP socket and you don't have any guarantee that the clients receive the file.

  • does each client listen on TCP port 8123 (so the server has to connect again to the client who asked for the file in the first place?) - this is not a very good idea, because you already have a client-server connection established (on port 9123 - technically though, once you accept() a connection in the server, the communication moves from 9123 to an open high port) - you just need to spawn a thread which will send the file and the server socket can keep accepting connections from other clients. If you must receive requests on one port and send files on another (WHY?), just create a new socket after receiving the request, connect it to the client, and send the file through it - but you really need to consider why you are implementing it like that.

laura