I'm looking for a good example of a simple TCP server/client that can deliver messages from one client to another. I have looked at many examples, but I can only find really complex ones, or one's where only one client talks to the server and back, and not to each other.
1 Answer
See selectserver.c at http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html. Clients are defined earlier on the page and server seems pretty easy to expand.
2 Comments
Jon Blake
That one is good but it doesn't have an example of 2 clients communicating to each other.
Greg Inozemtsev
@JonBlake That's because it's impossible with TCP sockets. You need one side to create a listening socket ("be a server") and the other to connect ("be a client"). For connectionless transport look into UDP. Read section 2 in Beej's guide for more details.