Solved

C++ telneting

Posted on 1998-08-12
6
282 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
  • 4
  • 2
6 Comments
 

Author Comment

by:TRM
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:TRM
Comment Utility
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
Comment Utility
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
Comment Utility
OK. Thanks.  I'll give it a try

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

728 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

14 Experts available now in Live!

Get 1:1 Help Now