Winsock Client User Input

This is a discussion on Winsock Client User Input within the Windows Programming forums, part of the Platform Specific Boards category; Hi, Im trying to make a server app that can be telneted into. It works in that i can connect ...

  1. #1
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339

    Cool Winsock Client User Input

    Hi,

    Im trying to make a server app that can be telneted into. It works in that i can connect to it and i recive "welcome to server" and "User:" but i then want the user name to be typed then recived by the program. So after "User:" is displayed i told the program to recieve, im not sure if thats right. But when I type 1 character in without pressing enter the program recieves that letter and then disconnects me. How do i fix this so that a whole word can be enterend in the client and then the server will get the whole word into the varible r_buffer?


    Code:
    char msgs[200] = "Welcome To Server\r\n";
    r = send(sock2, msgs, strlen(msgs),0); 
       
    strcpy(msgs, "User:\r\n");
    r = send(sock2, msgs, strlen(msgs),0); 
    
    char r_buffer[20];
    r = recv(sock2, r_buffer, 20, 0);
    r_buffer[r] = 0;
    MessageBox(hWnd, r_buffer, "Prog", NULL);
    Thanks for any help

    Cheers
    TNT
    TNT
    You Can Stop Me, But You Cant Stop Us All

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    Cant the client store the chars into a buffer and then only send it when the user presses the enter key?

  3. #3
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339
    Hi Fordy.

    Im not programming the client you see. I am using telnet as the client so i cant chose what it does. I tested in with Windows XP dos telnet, and as im not controling what that does, i need to do it all from the server. Do you know how to do this?

    Thanks
    TNT
    TNT
    You Can Stop Me, But You Cant Stop Us All

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,855
    I'm not sure you can do this. All depends on the msg's you get from the telnet client.

    Sockets are event driven. Without some input from the client you can not tell if the user has finished typing, or has just paused, or if there is lag.

    Also there is no way of telling if the whole data has been received in one read by the server. It could be just some of the data sent has been read and there is more on the way/in the rec buffer.

    Ask the client user to give you a hint/msg that they have finished. Ask them to end each input with a terminator char (say 'zx'). Better yet get eh number of chars sent.

    Better still create your own telnet.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 01:20 PM
  2. SSH Hacker Activity!! AAHHH!!
    By Kleid-0 in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 03-06-2005, 02:53 PM
  3. vectors and user input
    By Chaplin27 in forum C++ Programming
    Replies: 6
    Last Post: 01-17-2005, 09:23 AM
  4. Nested Structures - User Input
    By shazg2000 in forum C Programming
    Replies: 2
    Last Post: 01-09-2005, 09:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21