Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 603
  • Last Modified:

Creating a telnet server with viscual c++ 5.0

env: win95  compiler:msvc++ 5.0

What I would like to do is create a telnet server using mfc (if practical). I've been giving this some thought and decided that use of a sdi would be best. I've alreay layed out what I think the shell should look like, but I'm compeletly lost with the acutal code for the server. This server will serve as a mud server. I'd like for it to handle as many ppl as my system can handle. I'm not sure what other info one would need to answer this question.
1. a telnet server using msvc++ 5.0
2. created as a SDI
3. will serve as a MUD/Chat server (nonirc)
4. run on win32 systems
5. if any more info is needed please ask.

as a side note, i do know the differences between stream, raw, and data sockets. I've been doing some reading of my own :) Thanks for your time.
1 Solution
Your best bet, since I have worked in developing software in this arena - is to use MFC's great CAsyncSocket (actually, your derived class from it) to handle the server "listening" socket, and create CAsyncSocket derived classes for each connection.  Since you're writing a SERVER, you should think about the end installed system OS, whether NT or 95 or 98...  the best performance and larget # of ppl you'd be able to handle would be on an NT system (either workstation or server).

Still, you should note that the server prolly would be _dedicated_ to use of your software, since it will be highly memory and process intensive in the end.

Read up on CAsyncSocket and threads.  Also, look at the source code for successful MUDs/MOOs like lambda moo (, and coolmud (don't know one specific ftp, but you can search for it at - the MUD resource site).

Examine how they handle sockets - note that you'll have it sooo much easier in MFC!

Also, you'll need a copy of BISON/FLEX ported to Win32 in order to compile a "parser" if you're going to allow any sort of programming of objects in your system.  You can get one from or from my site (note you'll need IE4.0 to view my site).  My port of bison runs _without_ any additional DLLs or LIBs.

If it's a server, you won't need an omnipresent UI, though a system tray icon would be nice so a "local admin" can right click on it for a menu to do things to it like stop it, or see who's on, or checkpoint/dump it.

There's a lot to think about, and it's no small project if you've no server writing experience.

BEST OF LUCK!  and let us all know how it goes!
NoiroiAuthor Commented:
While the information given by Igroove was informative, it was still lacking in the information I need. I've read up on CAsyncSocket and have books (by Kate Gregory) on the topic, but not on Telnet. I've looked at the code for various muds(rom, circle, mud++) but I need a MFC example to follow. I don't know _how_ to use it properly.
Noiroi, you can get a *huge* amount of information, as well as great advice from:

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

I've written a couple servers, and one of them happened to be a MUD. Here's my basic
development process for it:

The first thing to do would be to get your server working first of all.
Do a search on the web for "BSD SOCKET TUTORIAL". Winsock and Winsock2
follow the BSD Socket standard in certain respects. you may also try "VC++ SOCKET
TUTORIAL" so that you follow any MFC guidelines...

Once you have the server up, and listening, and it can accepts connections, then
decide on the "command set" you want to use for the MUD. Lot's of standard ones, and
if you're a MUD'er yourself, you are probably familiar with some already. like,
"kill <name>", "get <object>" and so on... basically, you want to read in their command,
parse the line, and determine which action to do based on their command.
NoiroiAuthor Commented:
Thank you for giving me more information to search on. I' going to reopen the question, because one can n'ver have too much information.
Basically what a telenet server does is this:
One thread ussually sits in an endless loop listening to a "Published port"  So for the first part of your design you need to choose a port number as your MUD connection port.  Create a main thread that listens on this port for connection requests.  When you get a request for a connection,  it is ussually a good idea to open another socket and have the main thread spin off a child thread to handle the regular data between the server and the clients.  The advantages of this are the fact that it becomes easy to dynamically allocate space for other users connecting and to manage them all.  It also lets you use the exact same code for all user data I/O.  The other advantage is your server dosn't block when it tries to accept a connection, and doesn't get hung by processing data through the socket since that is the responsibility of the child thread.  So for overview of the server's connection accepting scheme you have this:

Main thread opens a socket on a predetermined port
Main thread endlessly loops waiting for a connection request on the published port
When a connection is requested, open a new socket/port with a child thread to handle the data(this frees the original port, and puts main thread back in the original loop)

Now for your child thread.  What you need to do is define a standard set of commands.  The simplest idea involved in this is to use an integer.  Like an FTP server, for instance, you could  say a 1 is dir, a 2 is put, a 3 is get, a 4 is delete and so on.  Then you pass data through the sockets like you would write to a file.  You write to the socket as if it were a file handle, and you read from the socket as if it were a file handle.  

Now the tricky part comes in.  How do you know when there is data on the socket to be read, or if the socket is ready to be written too?  This will greatly depend on how you implement you sockets.  If you use CAsyncSocket, a lot of the above is taken care of for you.  If you want to use standard BSD sockets you need to use the standard iotcl(), or the Windows sockets versions of it(Win32, MFC, and so on)  Basically you will pass this function a map(implemented differantly in Winsock than in unix sockets) of the sockets you are worried about and the type of events you are worried about and the function will return telling you is there is any data to be read.  The specifics of this function are in the help depending on how you implement sockets.  I recommend using MFC if your not real familiar with network comms as the bulk of the work is done for you.  I recommend highly if you are a little familiar with network comms, Win32s, and Overlapped I/O to check out COverlappedSocket in "Win32 Network Programming" by Ralph Davis (Addison-Wesley Publishing 

Now, some details like how you intend to close the sessions, how you want the server to manage security and things like that, you still need decide.  That's kind of an overview of the way a standard servers works, i.e. listen to a port and spawn a worker thread.  Hope that helps, if it's not what you need please reject and let me know what your still missing.
NoiroiAuthor Commented:
Thank you for your response. Also, thank everyone for their respones, I appreciate the guidence provided. If anyone knows of some help reading material, please suggest it. Thank you again. Noiroi
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now