开发者

Winsock's send() works oddly

I'm trying to write an experimental server program that accepts a connection and sends a message to the cl开发者_如何学编程ient. 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?


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜