[英]Can server send response from a different process and socket?
After server, which is listening on port X, receives a request from the client, can it send response from a different process and a socket with sendto call. 在正在端口X上侦听的服务器接收到来自客户端的请求之后,它是否可以从其他进程和带有sendto调用的套接字发送响应。 Please note that the client also sends request with sendto (server address) call.
请注意,客户端还会通过sendto(服务器地址)呼叫发送请求。
Here are the steps: 步骤如下:
Both client and server knows each other ip addresses and port numbers. 客户端和服务器都知道彼此的IP地址和端口号。
I am noticing that client does not receive response when server sends response from a different process. 我注意到服务器从其他进程发送响应时,客户端未收到响应。 Otherwise, it does.
否则,它会。
This can be done but there are some major caveats. 可以这样做,但有一些主要警告。
The client must bind the socket and use sendto()
and recvfrom()
rather than connect()
'ing the socket and using send()
and recv()
. 客户端必须绑定套接字并使用
sendto()
和recvfrom()
而不是connect()
插入套接字并使用send()
和recv()
。 This allows it to receive incoming packets from anywhere as long as they are directed to the IP/Port that recvfrom()
is reading on. 这使它可以从任何地方接收传入的数据包,只要它们被定向到
recvfrom()
正在读取的IP /端口即可。
If there is a firewall or NAT in the path between client and server, it is likely to block the response since the sending IP/Port does not match the IP/Port that the client originally sent its request to. 如果客户端和服务器之间的路径中存在防火墙或NAT,则可能会阻止响应,因为发送IP /端口与客户端最初向其发送请求的IP /端口不匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.