Reputation: 451
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 received byte[] is a text or image ?
Upvotes: 0
Views: 195
Reputation: 35126
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
Upvotes: 1
Reputation: 182753
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.
Upvotes: 2
Reputation: 1499830
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.
Upvotes: 4