If the code should be simple, then you probably asking for C example based on traditional BSD sockets. Solutions like boost::asio
are imho quite complicated when it comes to short and simple "hello world" example.
To compile examples you mentioned you must make simple fixes, because you are compiling under C++ compiler. I'm referring to following files:
http://www.linuxhowtos.org/data/6/server.c
http://www.linuxhowtos.org/data/6/client.c
from: http://www.linuxhowtos.org/C_C++/socket.htm
Add following includes to both files:
#include <cstdlib>
#include <cstring>
#include <unistd.h>
In client.c, change the line:
if (connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0)
{ ... }
to:
if (connect(sockfd,(const sockaddr*)&serv_addr,sizeof(serv_addr)) < 0)
{ ... }
As you can see in C++ an explicit cast is needed.