简体   繁体   中英

how to find what is inside byte array?

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 ?

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

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