?
Solved

C++ telneting

Posted on 1998-08-12
6
Medium Priority
?
289 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 400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 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