简体   繁体   English

服务器如何知道客户端的端口号,它将使用它使用 Java 编程套接字将响应发送到客户端?

[英]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.

相关问题 如何使用来自服务器的随机数在客户端 JAVA SOCKET PROGRAMMING 上随机显示图像数组中的图像 - How to use random number from server to randomly display image from an array of images on client JAVA SOCKET PROGRAMMING 如何在不使用常规客户端-服务器套接字编程的情况下用Java发送字节? - How to send a byte in java without using the regular client - server socket programming? 套接字编程客户端服务器Java - socket programming client server java Java Socket编程服务器客户端 - java Socket programming Server Client 服务器无法将消息发送到客户端(Java线程套接字编程) - Server unable to send messages to client (java thread socket programming) 如何使用Java编程连接客户端计算机以使用安装在服务器计算机中的Sqlite数据库? - how to connect client computer to use Sqlite database which is installed in the server computer using java programming? 使用 TCP 连接(套接字编程)在 Java 中将 2D 矩阵从客户端发送到服务器 - Send a 2D Matrix from Client to Server in Java using TCP connection (Socket Programming) 使用Java中的套接字编程将数据流从客户端程序(在VM中运行)发送到服务器程序(在Host OS上) - Send stream of Data from client program (running in VM) to server program(on Host OS) using socket programming in Java 使用 WiFi 和 Java 套接字编程的服务器-客户端聊天 - server-client chat using WiFi and java socket programming 如何在Java中为Socket客户端获取动态端口号 - How to get the dynamic port number in Java for Socket client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM