This article was contributed by Lee Patterson.
This sample server demonstraites a server that can handle multiple TCP/IP connections. It also shows how to make a simple telnet server that could be used for things like administrating a server, making a chat room, or even creating a MUD.
The project that I chose was a chess server that could handle multiple games of Chess, with multiple players & watchers. This sample project uses a very handy blocking socket class called CBlockingSocket. The blocking socket class was found in the book titled Inside Visual C++ 5.0 by MS PRESS. This class is free, and can be used where ever, by whom ever. The class handles timeouts and errors by throwing an exception, so you aren’t checking for errors all the time.
In order to facilitate making a telnet server, I derived a CTelnetSocket class from CBlockingSocket to handle mundane tasks like reading an entire line of data from the socket & printing text to the socket.
This is a very simple console application that demontrates:
- Internet Server that accepts telnet connections.
- Using multiple threads to handle more then one connection.
- Blocking socket class for reading/writting/accepting connections from sockets.
(I’d recomend this class over the MS CSocket and such, as they still have some 16-bit stuff in them, and this class ports to Unix a lot easier. That was the main goal of my program.)
- Simple linked list class that can be used anywhere (unix/mfc app/console app).
Note: The linked list class is not thread safe.
The project and sample is included in ChessServer.zip. Use telnet as a client to connect to this server (ie: “telnet localhost”). You need to make sure your telnet client sends both CR & LF’s.
See server.cpp for additional comments.
Date Posted: July 21, 1999
Last Updated:July 21, 1999