Click here to Skip to main content
15,879,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I want to split a buffer of a large data into chunks while using websocket in c#.

I am trying to send over a web socket but I am not getting the entire data.
byte[] buffer = encoding.GetBytes(stringtoSend); I want to split it as chunks to the server side from client.

What I have tried:

Core Code is as below:
byte[] buffer = encoding.GetBytes(stringtoSend);

                   bool EndofMessageStatus = false;



                 await webSocket.SendAsync(new ArraySegment<byte>(buffer), WebSocketMessageType.Binary, EndofMessageStatus, CancellationToken.None);
Posted
Updated 16-Jul-18 21:35pm

1 solution

If you have problems at the receiving side, sending data in chunks will not solve them. It will make your code more complex and might introduce new problems.

Try to solve the receiving problems instead.

I can only guess here:
You are sending a string and have problems to detect the length when receiving. Then send the length of transferred data first followed by the payload. So the receiver knows how many data he has to receive. Defining such is called a "protocol" and common for socket communications.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900