Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C++ telneting

Posted on 1998-08-12
6
Medium Priority
?
290 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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.
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.

610 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