0

I'm trying to write an experimental server program that accepts a connection and sends a message to the client. I got the client to connect, but I can't seem to send the message without doing really odd things.

For example, in this snip, conn is a connected socket:

int sendRes;
char buf[1024];
strcpy_s(buf,"Testing!");
sendRes = send(conn,buf,strlen(buf),0);
Well, when I connect to it via Telnet, it displays nothing and just quits. However, when I add the line cout << sendRes to the end of this snip, it suddenly works and displays Testing! on Telnet, just like it should.

And so, I would like to ask anyone who knows, why is it acting like so?

  • 1
    I assume you call shutdown and closesocket in your app? some of the data might not be sent before you call shutdown. Also check what goes over the wire with WireShark or Netmon. – seva titov Mar 26 '11 at 07:56

1 Answers1

1

Could it be that the telnet client itself is waiting for an end of line marker to display the incoming buffer?

Try writing your own client and using recv to see if anything is incoming.

Then again, new line might not have anything to do with it since the cout is on the local side.

Try checking RFC854 for the full telnet specification (or, again, simply write your own client).

Aviad P.
  • 32,036
  • 14
  • 103
  • 124
  • I was going to say the same, but I wasn't sure if that was the culprit or not. Why would the `cout` make a difference? Time for it to flush the network data stream? A little more context as to how/when the sockets are opened/closed would be helpful here. – Will Mar 26 '11 at 07:55