简体   繁体   中英

Strange issue with NetworkStream and reading the first two bytes of a message

I am running into this strange issue where reading the first two bytes of a TCP message can take 5-10 seconds (after accepting the connection) but reading the rest of the message is almost instant.

This only seems to occur when receiving requests from an external integrator, no issues with reading requests from inside the network or even from my computer at home. Because of that I am assuming it is a network issue with us and them.

An network issue could take forever to resolve so I am hoping there is something I could fix with my code.

NetworkStream networkStream = client.GetStream();

byte[] lengthHeader = new byte[2];
stream.Read(lengthHeader, 0, 2);
int length = lengthHeader[0] * 256 + lengthHeader[1];

byte[] buffer = new byte[length];
stream.Read(buffer, 0, length);

Never mind.

Was a miscommunication issue between me and the other guy. Turns out he was expecting a persistent socket connection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM