ServerSocket 是否为每个连接创建一个新套接字?
Does ServerSocket create a new socket for each connection?
我阅读了 Socket tutorial 中的以下声明。
If everything goes well, the server accepts the connection. Upon
acceptance, the server gets a new socket bound to the same local port
and also has its remote endpoint set to the address and port of the
client. It needs a new socket so that it can continue to listen to the
original socket for connection requests while tending to the needs of
the connected client.
以下是我的问题:
- 请纠正我上面的理解 - 我通过指定端口打开一个套接字 (
ServerSocket
),比方说 8001,现在我的服务器将开始侦听此端口上的请求,现在它从一个客户端,类似于 http://abc:8001/test
,所以一旦它接受连接,它就会创建一个本地端口,比如说 10001,所以现在这个客户端请求将在 10001 上被接受(或者换句话说,与客户端的连接将通过端口建立10001) 而 8001 将再次空闲并监听新请求?
- 那么,这是否意味着我用
ServerSocket
指定的原始端口将永远不会用于建立连接?
- 那么,这是否意味着如果我与客户端建立连接,比如说通过端口 9001,那么在同一个 9001 端口上永远不会再发生任何通信(或者换句话说建立连接),直到原要求我的配餐完成了吗?
请随时详细说明这些问题的概念,这不仅对我有帮助,对未来的访问者也有帮助。
Does ServerSocket
create a new socket for every connection?
是的。
I open a socket (ServerSocket) by specifying a port, lets say 8001, now my server will start listening to requests on this port, now it gets a request from a client, something like http://abc:8001/test, so once it accepts the connection it will create a local port lets say 10001,
没有
so now this client request will be entertained over 10001
没有
(或者换句话说,与客户端的连接将通过端口 10001 建立)
没有
while 8001 will again be free and listening for new requests?
是的。
So, does it means that original port I specified with ServerSocket will never be used for establishing connections?
没有
So, does it mean that if I having a connection with a client, let say over port 9001, then there can never be one more communication happening (or in other words connection established) on the same 9001 port until the original request I am catering is completed?
没有
接受的套接字使用与侦听套接字相同的本地端口,完全按照您引用的文本。
根据您的问题,您混淆了新套接字和新端口。
我阅读了 Socket tutorial 中的以下声明。
If everything goes well, the server accepts the connection. Upon acceptance, the server gets a new socket bound to the same local port and also has its remote endpoint set to the address and port of the client. It needs a new socket so that it can continue to listen to the original socket for connection requests while tending to the needs of the connected client.
以下是我的问题:
- 请纠正我上面的理解 - 我通过指定端口打开一个套接字 (
ServerSocket
),比方说 8001,现在我的服务器将开始侦听此端口上的请求,现在它从一个客户端,类似于http://abc:8001/test
,所以一旦它接受连接,它就会创建一个本地端口,比如说 10001,所以现在这个客户端请求将在 10001 上被接受(或者换句话说,与客户端的连接将通过端口建立10001) 而 8001 将再次空闲并监听新请求? - 那么,这是否意味着我用
ServerSocket
指定的原始端口将永远不会用于建立连接? - 那么,这是否意味着如果我与客户端建立连接,比如说通过端口 9001,那么在同一个 9001 端口上永远不会再发生任何通信(或者换句话说建立连接),直到原要求我的配餐完成了吗?
请随时详细说明这些问题的概念,这不仅对我有帮助,对未来的访问者也有帮助。
Does
ServerSocket
create a new socket for every connection?
是的。
I open a socket (ServerSocket) by specifying a port, lets say 8001, now my server will start listening to requests on this port, now it gets a request from a client, something like http://abc:8001/test, so once it accepts the connection it will create a local port lets say 10001,
没有
so now this client request will be entertained over 10001
没有
(或者换句话说,与客户端的连接将通过端口 10001 建立)
没有
while 8001 will again be free and listening for new requests?
是的。
So, does it means that original port I specified with ServerSocket will never be used for establishing connections?
没有
So, does it mean that if I having a connection with a client, let say over port 9001, then there can never be one more communication happening (or in other words connection established) on the same 9001 port until the original request I am catering is completed?
没有
接受的套接字使用与侦听套接字相同的本地端口,完全按照您引用的文本。
根据您的问题,您混淆了新套接字和新端口。