TCP/IP Client and Server on the same machine

I have a QNX machine that needs to send and receive status messages over an ethernet link to another machine using TCP/IP (or maybe UDP).

Do I need to create two processes on the QNX machine?
One as a server to receive status messages from the other machine,
and second as a client to send status messages to the other machine?

or am I better off to use UDP?

Thanks.

Well regardless, you could use two processes or two threads to do this. If the messages are asynchronous then this is probably the best way to do it. On the other hand, if it is synchronous communication, you send a message and then wait for a message, you can do it with one thread. Usually you wait for the response with a timeout in case it never comes.

The choice of TCP/IP or TCP/UDP depends on other issues. If the messages are short and efficiency is important then UPD is probably a good way to go. In a local network the reliability of receipt is functionally if not theoretically about the same. If your messages are long and you are going over the internet or a network less than perfectly reliable then TCP may be better.

With notification ( select() ) and non-blocking socket you can do that in one process/thread.

Thanks for the replies.
The messages are asynchronous. My confusion is; as this is a peer-to-peer connection over TCP/IP, does it matter which machine is server versus client?
Is it possible to have only a client process on one machine, and a server process on the other machine and have a bi-directional communication? Can server send messages without client asking for it once a connection is made?

It might matter which machine is the server. For example, if the client uses DHCP it might be tricky to find out where it is.
Once the connection is made, it is bi-directional. The server can send messages without the client asking. There isn’t any way other than by convention that the client could ask.

So server / client distinction is required to set up the connection. But once the connection is set up, server can also send messages without the client asking and vice versa.

Is there simple code samples for server and client setup and usage in QNX? I couldn’t find any in the QNX documentation. I am using QNX 6.3.0 Service Pack 3.
Thanks.

Typically the client is the one seeking out the server, and establishing the connection to it. Once that is done, the flow of data is bi-directional and asynchronous.

You didnt look hard enough (unless its not in 6.3.0). Check with GOOGLE, this type of programming is independant of QNX, any Unix code will do just fine.

A simple example in TCP/IP and UDP

beej.us/guide/bgnet/output/html/ … erver.html

A slightly more complex example of a multi user chat server.

beej.us/guide/bgnet/output/html/ … anced.html

These will cut/paste and compile in QNX.

Tim

Thanks. the examples there are very useful.