[英]How the server knows the port number of the client in which it will use it to send the responses to the client using java programming socket?
In socket programming using java , we need to specify in the client side the port number in which it will communicate through it with the server using the socket class .在使用 java 的套接字编程中,我们需要在客户端指定端口号,通过它与使用套接字类的服务器进行通信。 On the other hand , in the server side , we don't need to specify the client port number through which we will send our responses to the client , we just create a port number through which we will listen to the request and we just wait for this request to arrive using the accept () method.另一方面,在服务器端,我们不需要指定将响应发送到客户端的客户端端口号,我们只需创建一个端口号,通过它我们将侦听请求,然后等待使用accept()方法让这个请求到达。 So please someone explains how the responses are sent from server to clients although we don't specify the client port number ?所以请有人解释如何将响应从服务器发送到客户端,尽管我们没有指定客户端端口号?
Both TCP port numbers are in every TCP segment.两个 TCP 端口号都在每个 TCP 段中。 When the incoming TCP connection is accepted at the server, the server (specifically the TCP protocol implementation in the server) knows all it needs to know to respond to the client.当服务器接受传入的 TCP 连接时,服务器(特别是服务器中的 TCP 协议实现)知道响应客户端所需的所有信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.