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
Of course..when I do that it prints out like the whole string again and again.
//You get the picture.
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....
#include <ctype.h> /* For isprint() */
while ((nBytes = recv(blah...)) > 0)
printf ("We received %d bytes\n", nBytes);
for (i = 0; i < nBytes; i++)
printf ("%c ", isprint(buf[i]) ? buf[i] : '.');