Click here to Skip to main content
13,454,150 members (55,677 online)
Click here to Skip to main content
Add your own
alternative version


74 bookmarked
Posted 24 Nov 1999

Multithreaded TCP/IP Telnet Server - Chess Game Example

, 22 Jan 2001
Rate this:
Please Sign up or sign in to vote.
Chess Game Example

Sample Image


This sample server demonstrates 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 demonstrates:

  • Internet Server that accepts telnet connections.
  • Using multiple threads to handle more then one connection.
  • Blocking socket class for reading/writing/accepting connections from sockets. (I'd recommend 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.)

Also included

  • 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 Use telnet as a client to connect to this server (i.e.: "telnet localhost"). You need to make sure your telnet client sends both CR & LF's.

I'd be happy to field any questions about the workings of the server, or how I set things up, but I'm not interested in fixing up this server, or fixing any of the "chess game" bugs. Any bugs found in the socket classes I would be interested in, although they are thoroughly tested.

I built this server one night as a demo for a company in hopes of getting a job there. Didn't know a damn thing about sockets so I used, and built upon a blocking socket class that was found in Inside Visual C++ 5.0 by MS PRESS.M

There are no rules to either game, so players can move whatever piece to whatever square. There isn't even any error checking, and you can't backspace. This is a very limited server in that respect.

The layout of the server is:

  1. Create an Accept thread to accept connections on port 23 (telnet)
  2. Get a connection, create a new accept thread to be able to handle more connections.
  3. Log this person in, getting user name.
  4. Create a lobby of sorts where you can do simple chat, create a new game, join a game, or watch a game.
  5. This lobby reads a line of input from the socket, and then checks what the command the user typed was via ParsCmd.
  6. When the person creates a game, we add the game object to a pending list, and wait for someone to join the game.
  7. When a person joins a game, we check for the game name on the pending list, and assign that person as the second player on that game object.
  8. When you WATCH a game, you are added to a list of watches on that game object.

The game objects:

The base class is the BoardGame class. Chess and Checkers games are derived from BoardGame. This is to make a consistent interface for adding players to a board game, and drawing the board.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Lee Patterson
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 1 Pin
shenf20-Dec-12 14:44
membershenf20-Dec-12 14:44 
General[Message Deleted] Pin
it.ragester2-Apr-09 21:57
memberit.ragester2-Apr-09 21:57 
Questionhow do i run this program Pin
abhilash934-Mar-09 0:27
memberabhilash934-Mar-09 0:27 
GeneralWorks Fine Pin
AngelPortal24-Nov-06 1:02
memberAngelPortal24-Nov-06 1:02 
Generalis this code support in llinux Environment Pin
sheladiya chetan28-Aug-06 18:06
membersheladiya chetan28-Aug-06 18:06 
GeneralChinese symbols Pin
haha6244-May-05 21:31
memberhaha6244-May-05 21:31 
Generalwant a free server to test online card game like Rummy Pin
Pongsak Maneekul18-Jul-04 21:43
sussPongsak Maneekul18-Jul-04 21:43 
QuestionHow to send message to one client Pin
Anonymous12-May-03 18:06
sussAnonymous12-May-03 18:06 
GeneralChess game Pin
Redeemed2-Apr-03 14:45
memberRedeemed2-Apr-03 14:45 
GeneralRe: Chess game Pin
Iceman2-Apr-03 15:25
memberIceman2-Apr-03 15:25 
GeneralRe: Chess game Pin
wait15-Oct-04 1:00
memberwait15-Oct-04 1:00 
GeneralRe: Chess game Pin
pegasusplus8-Jun-05 0:40
memberpegasusplus8-Jun-05 0:40 
QuestionHey aint we brothers? Pin
Pat Patterson5-Jun-02 5:21
memberPat Patterson5-Jun-02 5:21 
GeneralSmall bug maybe Pin
Anonymous20-Feb-02 12:59
memberAnonymous20-Feb-02 12:59 
GeneralRe: Small bug maybe Pin
Anonymous11-Nov-02 17:54
sussAnonymous11-Nov-02 17:54 
GeneralRe: Small bug maybe Pin
patarak31-May-04 20:12
memberpatarak31-May-04 20:12 
GeneralRe: Small bug maybe Pin
AngelPortal24-Nov-06 0:23
memberAngelPortal24-Nov-06 0:23 
QuestionAlternative Telnet implementations ? Pin
Rob W20-Jul-00 9:49
sussRob W20-Jul-00 9:49 
AnswerRe: Alternative Telnet implementations ? Pin
Anonymous16-Jun-01 17:06
memberAnonymous16-Jun-01 17:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03-2016 | 2.8.180321.1 | Last Updated 23 Jan 2001
Article Copyright 1999 by Lee Patterson
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid