This archive contains C source code sample implementations of clients and servers using Berkeley Socket. Most of the source code evolved from code that I originally wrote back in 1990. Every few years I was using it as a reference and updating it to replace obsolete functions with modern functions. I've placed the resulting code on github so that I could find it and access it from just about anywhere.
These files are released under the BSD License.
More information on Berkeley sockets and this echo server implementation may be found at: https://michaeldipperstein.github.io/sockets.html
File Name | Contents |
---|---|
echoclient.c | TCP/IP echo client example using getaddrinfo() to find the server address |
echoserver.c | TCP/IP echo server example with poll() loop |
echoclient_udp.c | UDP/IP echo client example using getaddrinfo() to find the server address |
echoserver_udp.c | UDP/IP echo server example |
Makefile | makefile for this project (assumes gcc compiler and GNU make) |
README.MD | This file |
To build these files with GNU make and gcc:
- Open a terminal
- Change directory to the directory containing this archive
- Enter the command "make" from the command line.
NOTE: It is not possible to mix and match TCP and UDP client/server pairs.
echoserver <port number>
echoserver_udp <port number>
The echoserver
will not exit until CTRL-c
is pressed.
echoclient <server hostname or address> <port number>
echoclient_udp <server hostname or address> <port number>
Hit Enter
on a blank line to exit from an echoclient
.
Multiple echoclient
s may connect to a single echoserver
instance.
12/27/17
- Initial release
12/30/17
- Added UDP client and server examples
08/08/20
- Added polling and signal handling to allow UDP examples to exit cleanly when waiting to receive data
08/18/20
- Rewrote TCP code so that the
echoserver
will echo a message will be echoed to every connectedechoclient
. - TCP
echoserver
now actively tracks all connectedechoclient
sockets. - Replaced
select()
loop withpoll()
loop in TCP code.
08/30/20
- Rewrote UDP code so that the
echoserver
will echo a message will be echoed to every connectedechoclient
. - UDP
echoserver
now actively tracks allechoclient
socket addresses.- Address is obtained when client sends its first message.
- Address is released when the client sends and empty message.
- Replaced
select()
loop withpoll()
loop in USP code.
- Send and receive messages of any size
- Apply timeout to client connect attempts
- Add support for IPv6
- No known bugs
Michael Dipperstein (mdipperstein@gmail.com)