Solved

C++ telneting

Posted on 1998-08-12
6
288 Views
Last Modified: 2010-04-02
I have RedHat linux. I want to know how to make a telnet server that will accept MULTIPLE REQUESTS at one time. I know how to already make a single user telnet server, where one user can telnet in, and when they give the quit command, such as returning 'q' to the server, they will be disconnected and the server will die.

I think I know just a tad on making multiple user Telnet servers. File descriptors. A VERY SIMPLE chat server would be appreciated,
thanx
ty
0
Comment
Question by:TRM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 

Author Comment

by:TRM
ID: 1170106
Lemme rephrase that last part: I know little on multiple user telnet servers: I know File descriptors are involved. I have no CLUE to what they are.
0
 
LVL 3

Accepted Solution

by:
sailwind earned 200 total points
ID: 1170107
File descriptors is a integer that represent the I/O location to read/write information.
In our case, we would be using socket descriptors (a type of descriptor) to define our
connection to the socket.

The general idea is:

-setup the socket to listen to
-wait for a connection on that socket
-when a connection is established on a new socket
-fork off a child process to do handle the communication
     through that new socket. Make sure you close off the
     original socket.

Here's a psedocode:

program multiConnection {

int sockfd;         // socket to listen connection requests from
int newsockfd;   // new socket to to with when connection is establshed
int childpid;       // child's process id

      Create and bind(sockfd);      // generate our socket based on protocol and port
      Listen(sockfd);                    // wait for connection on this socket

      for(infinity) {
           newsockfd = accept(sockfd); // connection request received, generate new socket
                                                      // to talk to client
           childpid=fork();                     // create a child to handle the communication
           if(childpid == 0) {                  // if it is child          
                 close(sockfd);                // close the parent's socket
                 doaction();                     // do the communication activities
                 exit(0);                          // when communication is done, kill the child
            } // if

            close(newsockfd);               // close the newly opened socket
     }
}
     



0
 

Author Comment

by:TRM
ID: 1170108
It helps, but i would like to have some more actual code. I, currently, am using(in my program), socket(), bind(), listen(), and accept(). Remember : i know how a single user can connect w/out using any file descripters or anything. i want to know how to let several different users connect, then have my program send inputed data from one to the output of another. thanx.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:TRM
ID: 1170109
It helps, but i would like to have some more actual code. I, currently, am using(in my program), socket(), bind(), listen(), and accept(). Remember : i know how a single user can connect w/out using any file descripters or anything. i want to know how to let several different users connect, then have my program send inputed data from one to the output of another. thanx.
0
 
LVL 3

Expert Comment

by:sailwind
ID: 1170110
Here's an example of multi-node server. It can handle mutliple connections but there
is no way for each connection to display the information to another. The only way
I can think of is to have each child process alert the parent of the message to update
and send to other connections.

The code is taken from UNIX Network Programming by W. Richard Stevens.
A great book, one that every network engineer should have. I'm including the
multiple connection part. Remember, the file descriptor is just the socket descriptor.
So you're already using it but didn't know.

listen(sockfd, 5);

for(;;) {
  clilen = sizeof(cli_addr);
  newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
  if(newsockfd < 0)
    err_dump("server: accept error");
  if((childpid = fork()) < 0)
    err_dump("server: fork error");
  else if(childpid==0) {
    close(sockfd);
    str_echo(newsockfd);   // the actual running function
    exit(0);
  }

  close(newsockfd);
}

There, reads just like my pseudocode :)

0
 

Author Comment

by:TRM
ID: 1170111
OK. Thanks.  I'll give it a try

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

717 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