An Internet Chat Server
Building a Telnet-based Chat system in C
By Andrew Davison
One of the most popular Internet pastimes is connecting to a chat or talker server, strolling into a room of interesting people, and spending a few hours talking about meaningful (or perhaps not so meaningful) topics. This article outlines the key features of a simple chat server written in C. I'll concentrate on the networking aspects, but will also examine the implementation of a few user commands. The complete program, chat.c, is available electronically; see "Source Code" and fivedots.coe.psu.ac.th/~ad/code/chat/chat.c.
To join in a chat session, a user connects to the chat server via telnet. After typing a (unique) name, the user can move around the chat rooms, listening to or taking part in conversations. Online help is available, as well as general information about the rooms. Upon entering a room, the user gets a short description, along with a list of the other people in the room and the most recent public conversations. A user can talk to everyone in the room, have a private conversation (so long as the other person agrees), or send email to the chat superuser (useful for reporting the misbehavior of other visitors).
The superuser has additional "powers." He or she can terminate a visitor's connection, send superuser warnings, and ban users from the server. (Actually, the banning applies to the client's host machine, which is a little Draconian, but easy to code.) The superuser can also shut down everyone's connection (perhaps prior to closing down the server) and view user details kept by chat.