Jerry Meng
Jerry Meng

Reputation: 1506

Python socket client and server

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?

Upvotes: 1

Views: 360

Answers (1)

Robᵩ
Robᵩ

Reputation: 168836

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.

Upvotes: 0

Related Questions