Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Odd behavior of simple echo server....

hi all.. i'm new to the site, so i thought i start off with a quick question. i wrote the following simple echo server on redhat 9. the odd behavior pertains to the printing of status messages. first off.. here's some of the code:

--------------------------------------------------------------------------
sd_daemon = socket(AF_INET, SOCK_STREAM, 0);
if(sd_daemon<0)
{ ERROR CONTROL }

printf("
Socket Created...");
...
if(bind(sd_daemon,(struct sockaddr *)&id_daemon, sizeof(id_daemon))< 0)
{ ERROR CONTROL }

printf("
Socket Bound...");
-----------------------------------------------------------------------
ok ... these two messages print out just fine, here's the prob....
-----------------------------------------------------------------------
...
if( listen(sd_daemon,5) < 0)
{ ERROR CONTROL }

printf("
Socket Listening...");
printf("
*** TEST ***");
...
sd_x1 = accept(sd_daemon, (struct sockaddr *)&id_x1, &id_x1_len);
if(sd_x1 < 0)
{ ERROR CONTROL }

printf("
Connection Accepted from %s", inet_ntoa(id_x1.sin_addr));
printf("
*** TEST ***");
...
byte_count_recv = recv(sd_x1, &buffer, 100, 0);
------------------------------------------------------------------------
these messages also print out just fine IF the two "***TEST***" strings are in place. if they are removed, the "Socket Listening" message doesn't print until a connection is ACCEPTed - and the "X-tion Accepted" message doesn't print until data is RECVed on the socket. i'm just curious to know what's going on here... can anybody help?
full source available on request
thanks in advance
-chase
Sign In or Register to comment.