I have a TCP Socket server sending byte[] to the client, how can i find what received on the client? Server can send images, text both using Socket.Send(byte[])
is the recei开发者_如何学JAVAved byte[] is a text or image ?
It's a byte array. It's just bytes. If you know the image formats it might send you can check whether the byte array that's received looks like an image, but fundamentally you're just sending data. If the client needs metadata to know what it should do with the data, then send that as well.
Before you write any code that uses TCP, you need to design a protocol. The protocol should specify, at the byte level, exactly what goes over the connection. If the server knows what it's sending, it should tell the client somehow, and the protocol should say how.
If its image send a 0 byte otherwise 1 byte then send the data
You might want to send the length of data before actual data in 4 bytes. You can use BitConverter class for writing and reading int in byte array
精彩评论