Solved

Socket programming (how to program Telnet friendly sockets....)in C++ for MUD type games

Posted on 2003-12-11
5
2,764 Views
Last Modified: 2012-06-27
I have done an small app that should act as an MUD server in future, i have only programmed things like an socket accepting connections and multithreading stuff. But there is an problem!

The server crashes when i have connected with an standard Telnet client and typing a character,
the Telnet client sends the typed character immedlity and not as an string.

I have followed an tutorial that shows how to programm sockets etc.. and i have done one server and one client app that works perfectly together, but i also want the server to be compatible with Telnet. I cannot find any tutorial that cover how to do an Telnet compatible socket, is there any special arguments needed, data types or some sort of emulation?

Another thing, i have an Main loop and an socket-function pending as an Thread, I have tried to do an function to send data to the client but have failed. Is there some way to read some data(from a file, variable etc..) and send it to the client thro the Main loop, for example.

//Main Loop
for(;;)
{
     if(QUIT)
       break;
   
      check for incoming data();
     load some data from a file or some variable....();
      send data to client();
}

I want the app to be capable to get an string from the client and send some back to it, and it should be Telnet compatible. The main function of the app is to function like an MUD!

The app is only for learning , if could mail the code if you(The helper) need it to help me...

And some good links to MUD programming tutorials should be great.!
0
Comment
Question by:MaStA_Da_Vinci
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 9919990
Hi MaStA_Da_Vinci

I remember doing some socket progrraming for a server and telnet being client and it worked perfectly

Why is you code failing

Let us know more details

Amit
0
 
LVL 4

Accepted Solution

by:
skypalae earned 210 total points
ID: 9920226
Hi MaStA_Da_Vinci,

Telnet protocol specifies some special codes for exchanging more server/client informations, like terminal type, terminal size etc., etc. All of these codes start with '0xff' and 2 or more bytes follow. Detailed specification of such codes can be found in so called RFC documents (not only telnet specification, but also http, ftp and i think all of network communication can be found there). RFC 854 specifies basic telnet protocol. If you follow that you should be able to write telnet client as well as telnet server.

As far as i remember for each client request you have to answer at least that you won't support such functionality. The crashes are possibly not because of one character only (you should store the characters and when 'CR/LF' arrives flush the buffer to the MUD), but because of processing byte 0xff

Cheers!
0
 
LVL 4

Expert Comment

by:skypalae
ID: 9920234
MaStA_Da_Vinci,
another site worth to look at is http://www.scit.wlv.ac.uk/~jphb/comms/telnet.html
0
 

Author Comment

by:MaStA_Da_Vinci
ID: 9920316
Hi!

I think it have something with Telnet's STREAM functions, I have heard that Telnet have varius ways to send data. It could be possible that i send the wrong arguments to the client that tell Telnet to send every typed character!

I have found some Servers written in C++ that work with telnet, but they use some libarys i don't have and that i don't think is neccesary.  
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
I think these is to handle the TCP/IP, none of the problem i have.
And i think i doesn't have them, Iam using Ms Visual Studio 2003 Trial!
It could be some headerfiles used in Linux, iam also programming in Linux to but i decided to learn sockets in windows first.  

There could be some other way to handle the incoming data, iam using th function recv() th get data from the client and save it to an (array)buffer[] of "messagesize". I shouldn't need to get a single char at the time, i should be able to get an string but Telnet sends imm when an button i pressed.

I could do an function that store single char's into an array and later compare it with Specified commands in another array, then i have an simple parser but very complicated.
0
 

Author Comment

by:MaStA_Da_Vinci
ID: 9920351
Hmm...!
Thats sound intressting, iam going to take a look at the RFC.
And ofcourse... take an FAT cup of COFFE.

It doesn't hurt with more solutions, so you who have something to say write it here imm!


Thanks to you all that helped!

;-)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now