c++socketsnetwork-programmingtcpberkeley-sockets

Very Simple C++ TCP Echo Server


I am new to C++ network programming but have experience with Java sockets etc.

I have been trying to write a simple TCP echo server in C++ but cannot really make any progress. I've tried looking at some code like at http://cs.baylor.edu/~donahoo/practical/CSockets/practical/ but cannot get anything to work.

Can anyone give me some simple C++ code to get started with for something like a TCP echo server? I do not really understand how to even get started.

Thanks in advance.


Solution

  • The terms "simple" and "C++ TCP Echo Server" don't belong together in the same sentence. There is no such thing.

    The sample that you are looking at is probably as close to "simple" as you're going to get (if you want to get into the nitty-gritty). Using a library that handles all the heavy lifting for you would make things easier (but far less educational). I would probably check out Boost.Asio (and the example Blocking TCP Echo Server example).

    If things aren't making sense, you should probably go back and brush up on your C++ network programming until you get to the point that things start clicking.