开发者

How do I serialize telnet like communication on a bidirectional socket connection?

I have implemented TCP/IP communication between a VB and VC++ programs running on the same machine. On the VC++ side I spawn a thread which listens for connections. On the VB side I use the Winsock API to connect to the C++ server. Everything seems to work fine, especially when I manually debug and step through th开发者_高级运维e communication. The protocol is text based, commands terminate on '\n' and may or may not have an answer.

And here is the problem. I'm trying to implement commands which are sent to the server, this requires some processing and the server sends them back to the client. Under simple conditions this works fine, but under heavy load or different machine configurations sometimes the communication gets interrupted.

The client may be sending a command but the server may be sending the answer of a previous command. The VB client somehow gets a fragmented answer (say, instead of a "DATA RECEIVED" it gets "EIVED") which breaks the state machine I've implemented to track the connection.

So yeah, client and server are talking at the same time and this is making a problem. How do I serialize or queue this communication? I understand this would be similar to the problem of network packet collision on ethernet.


Rather than packet collision, my guess would be that you're reading more than you expect from the socket. Could it be that your last read from the socket looks something like

OTHER STUFF\nDATA REC

and on the next read you get "EIVED"?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜