Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You must set a delimiter at the end of your image, some set of bytes that will sinalize the server that the image has ended. It's also known as <strong>end of file</strong> (EOF) or <em>end of message</em>. TCP won't split the image into logical packets for your app, so you must write your own control of information.</p> <p>The logic would be similar to this: <strong>CLIENT</strong></p> <pre><code>byte[] EndOfMessage = System.Text.Encoding.ASCII.GetBytes("image_end"); byte[] ImageBytes = GetImageBytes(); byte[] BytesToSend = new byte[EndOfMessage.Length + ImageBytes.Length]; Array.Copy(ImageBytes, 0, BytesToSend); Array.Copy(EndOfMessage, 0, BytesToSend, ImageBytes.Length, EndOfMessage.Length); SendToServer(BytesToSend); </code></pre> <p><strong>SERVER</strong></p> <pre><code>byte[] EndOfMessage = System.Text.Encoding.ASCII.GetBytes("image_end"); byte[] ReceivedBytes; while(!IsEndOfMessage(ReceivedBytes, EndOfMessage )) { //continue reading from socket and adding to ReceivedBytes } ReceivedBytes = RemoveEndOfMessage(ReceivedBytes, EndOfMessage ); PrintImage(ReceivedBytes); </code></pre> <p>I'm at work right now and I can't provide a full running example, I'm sorry.</p> <p>Regards</p> <hr> <p>Support methods:</p> <pre><code>private bool IsEndOfMessage(byte[] MessageToCheck, byte[] EndOfMessage) { for(int i = 0; i++; i &lt; EndOfMessage.Length) { if(MessageToCheck[MessageToCheck.Length - (EndOfMessage.Length + i)] != EndOfMessage[i]) return false; } return true; } private byte[] RemoveEndOfMessage(byte[] MessageToClear, byte[] EndOfMessage) { byte[] Return = new byte[MessageToClear.Length - EndOfMessage.Length]; Array.Copy(MessageToClear, Return, Return.Length); return Return; } </code></pre> <p>Again, I couldn't test them, so you may find some bugs.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload