Question

I'm creating a server that will in most/all cases be run on the same machine as the client. The client will need to be able to send and receive messages from this server. Some of the received messages will not be answers to questions (such as with http requests). All the messages will hold is a string that the project then uses to determine what function needs to be run.

The question is "Do I need to connect on two ports: one for sending and one for receiving?" If I use tcplistener with C# and C++ POSIX for networking, can I just send and receive messages on the same port?

Was it helpful?

Solution

Yes. You can send and receive on the same port and that's the intended way to communicate with tcp.

EDIT

You have two actors, a host and a client.

The host... will open a local network port (that you specify) and listen for new connections and communications from clients.

The client... can (and probably should) choose it's own local port and connect to the host on the port you specified.

Both the host and client... can communicate over the established connection. The host can send data to the client as long as the client is listening.

OTHER TIPS

Have the server bind to and listen on a well-known port. Have the client bind to any port (you can let bind pick for you) and connect to the server on its port. Exchange messages.

Yeah, there isn't a difference between tcp/ip.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top