I want to avoid trimming of data send from a client to server interface via web socket. I am doing the connectivity and message sending with the client and server interface as separate Windows Application projects. I am able to connect with the server from client while sending smaller data. While sending larger volume of data, data is getting trimmed.
I increased the buffer size but still data is getting trimmed.
byte[] receiveBuffer = new byte[1024*4]
What I have tried:
Core Code as below:
Client lEVEL:
#region Send
private async Task Send(ClientWebSocket webSocket)
{
try
{
NeSTCommonClass.WriteTextFile(LogPath + Logfilename, "Client:Sending to Server Process Begins", true);
if (webSocket.State == WebSocketState.Open)
{
string stringtoSend = txtOutgoing.Text;
byte[] buffer = encoding.GetBytes(stringtoSend);
await webSocket.SendAsync(new ArraySegment<byte>(buffer), WebSocketMessageType.Binary, false, CancellationToken.None);
await Task.Delay(1000);
}
}
catch (Exception ex)
{
NeSTCommonClass.WriteTextFile(LogPath + Logfilename, "Client:Sending to Server Process Failed: " + ex.Message.ToString() + "", true);
}
NeSTCommonClass.WriteTextFile(LogPath + Logfilename, "Client:Sending to Server Process Ends", true);
}
#endregion
Server Level:
processing received data from Client is as below:
Processing the client level request from server as below;
byte[] receiveBuffer = new byte[1024 * 10];
WebSocketReceiveResult receiveResult = await webSocket.ReceiveAsync(new ArraySegment<byte>(receiveBuffer), CancellationToken.None);
var ServerstrReceived = System.Text.Encoding.Default.GetString(receiveBuffer);
txtIncoming.Text += Environment.NewLine + "Client:" + ServerstrReceived.ToString();
if (receiveResult.MessageType == WebSocketMessageType.Close)
await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None);