Java the difference of Socket and ServerSocket in using port

后端 未结 3 1581
独厮守ぢ
独厮守ぢ 2021-01-06 01:04

At the server side, we use

Socket server = serverSocket.accept();

to create a socket. After the socket is created, we can create a new thr

3条回答
  •  长发绾君心
    2021-01-06 01:28

    A ServerSocket can simply be seen as a Socket factory for incoming connections. For every incoming client connection, the ServerSocket.accept() method returns a new Socket to communicate with that and only that client on.

    In other words, any number of connections (limited only by the OS) can be made to the single ServerSocket, and each client connection will get a separate Socket to communicate on, all communicating using the same server side TCP port.

提交回复
热议问题