[英]How can I bind two sockets to the same port on two separate programs?
I have a server.java and a client.python file. 我有一个server.java和一个client.python文件。 When I try the following, however, I get a "[Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions" error. 但是,当我尝试以下操作时,出现“ [Errno 10013]尝试以一种受其访问权限禁止的方式访问套接字”的错误。 Is there a way around this? 有没有解决的办法? Why is this happening? 为什么会这样呢?
client.py client.py
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
sockRecv = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
sock.bind((socket.gethostname(),4000))
sockRecv.bind((socket.gethostname(),4000 + 1))
server.java 服务器.java
recvSocket = new DatagramSocket(4000);
sendSocket = new DatagramSocket(4000 + 1);
What your code is doing doesn't make sense, to me. 对我来说,您的代码在做什么是没有意义的。
The IP address + port represents an end-point for datagram communication. IP地址+端口表示数据报通信的端点。 If two applications were able to bind to the same end-point, which of them would receive the packets sent to the end-point? 如果两个应用程序能够绑定到同一端点,那么哪个应用程序将接收发送到端点的数据包? One of them? 其中之一? Both of them? 他们都?
UDP is not a multi-cast protocol .... unless you bind to a multicast IP address. UDP不是多播协议....除非您绑定到多播IP地址。
Based on hints in your code (names of variables) I think you are trying to set up message passing between two applications on the same host. 基于代码中的提示(变量名),我认为您正在尝试在同一主机上的两个应用程序之间设置消息传递。 If so you should do this: 如果是这样,您应该这样做:
There is no need for applications A and B bind to the same end-point; 无需将应用程序A和B绑定到同一端点; ie the same port ... to do what I think you are trying to do. 即相同的端口...做我想你想做的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.