Command Line App Sockets

This is a discussion on Command Line App Sockets within the Networking/Device Communication forums, part of the General Programming Boards category; Basically what I want to do is connect to a host, send some data then put all the received data ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    18

    Command Line App Sockets

    Basically what I want to do is connect to a host, send some data then put all the received data into a buffer and print it out as it comes...

    I know how to connect and send data, no problem.

    But my problem comes when trying to receive data.

    I mean with a command line application, how are you meant to like ..

    Let's say I use a loop

    Code:
    while (1)
    {
    recv(bla,bla,bla,bla);
    printf("%s");
    }
    //You get the picture.
    Of course..when I do that it prints out like the whole string again and again.

    What I need is like, ...

    A like char[] array, which can be filled up with characters, and like each time a character is retrieved via the socket, like it prints that character out.

    I guess basically what I am looking for, is where I can actually account the amount of characters received then end the loop after say 100 characters.

    Thank you in advance....

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Code:
    #include  <ctype.h>  /* For isprint() */
    
    while ((nBytes = recv(blah...)) > 0)
    {
      int i;
      printf ("We received %d bytes\n", nBytes);
      for (i = 0; i < nBytes; i++)
      {
        printf ("%c ", isprint(buf[i]) ? buf[i] : '.');
      } 
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. non-MFC DLL with MFC app question.
    By Kempelen in forum Windows Programming
    Replies: 10
    Last Post: 08-20-2008, 07:11 AM
  2. Sockets: send/receive continuous stream of data?
    By diddy02 in forum Networking/Device Communication
    Replies: 1
    Last Post: 08-09-2008, 12:52 AM
  3. best program to start
    By gooddevil in forum Networking/Device Communication
    Replies: 4
    Last Post: 05-28-2004, 05:56 PM
  4. pasword app
    By GanglyLamb in forum C Programming
    Replies: 2
    Last Post: 06-07-2003, 10:28 AM
  5. Starting window sockets
    By _Cl0wn_ in forum Windows Programming
    Replies: 2
    Last Post: 01-20-2003, 10:49 AM

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