0
votes

How do you communicate with a remote Server, who will always send his answer packages to your requests, to the IP/Port Tuple the requests come from ?

In TCP you will always need two sockets. One for the local Server and one for the local Client. As it is not possible to bind them to exactly the same port, let's say i bind the Server socket to port X and the Client socket to port Y. Now sending a request with the help of my local Client to the remote server, would cause that the remote Server respectively now the remote Client sends his answer to port Y, but my local Server is listening on Port X.

Neither i can use a single socket for sending and receiving, like in UDP, nor i can bind twice the same port.

1
Why do you need a local Server? If you are connecting to a remote Server you just create a local Client that sends request and handles writes on the socket. Look at this example from socket documentationplover
Thanks for your response. Are you talking about this: "data = s.recv(1024)" in my local Client ? I thought this would be a simple ack for my request if the remote server's response is in there this would solve my problem, i didn'nt mention that.user3305988
Yes the response would be written on the same socket. And you can read it using recv()plover
This would totally solve my problem. I will give it a try as soon as possible. If it works for me you could maybe write an answer so i can mark this thread to be solved by your answer. I appriciate your help. Thxuser3305988

1 Answers

0
votes

You don't need a local Server. The client can send and receive data to/from the Server over the same socket.

Check out examples in socket documentation and example of a client in the SocketServer documentation