1
votes

Well, I have a problem while doing socket programming in python.

What I used to do with socket is that, first creating a client socket and sending a HTTP GET request to a server and receiving the response from that server. It works fine.

Now my new idea is that I want to do it with two sockets, one send, one receive.

The sending socket is as usual, no surprise. The receive socket is a server which bind to the ipaddress used by sending socket.

The problem is I cannot receive any response from remote server. I used wireshark and see that remote server still sends back the data to the port which is used by sending socket. However, I cannot bind my receiving socket to the that port, since it is being used.

Is there anyway to achieve my scenario with two sockets? Do I have to bypass some system network protocol by using raw_socket?

1
Maybe zeromq is something for you. That abstracts all that nasty socket stuff for you. - RickyA
Can you expand on why you are doing this? What advantage do you perceive in having two sockets? Finally, are you trying to get this to work with existing servers, or are you modifying a server to this same two-socket protocol? - Robᵩ

1 Answers

0
votes

No, you cannot bind a receive socket to the same address as a distinct sending socket.

From the relevant Linux man page:

only one IP socket may be bound to any given local (address, port) pair.