Click here to Skip to main content
15,867,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am getting the end of message send from client to server side as false via web socket in asp.net with c#. I am sending a large data via web socket. For doing the same i am adding the bytes to the buffer while receiving the message.

What I have tried:

Core Code is as below:
ArraySegment<Byte> buffer = new ArraySegment<byte>(new Byte[8192]);

                        //if (result1.ToString() == "EOF")
                        //    result.EndOfMessage = true;

                WebSocketReceiveResult result = null;

                using (var ms = new MemoryStream())
                {
                    do
                    {
                        result = await webSocket.ReceiveAsync(buffer, CancellationToken.None);

                        //var result1 = msg.Substring(msg.Length - 3);


                        ms.Write(buffer.Array, buffer.Offset, result.Count);

                    }

                    while (!result.EndOfMessage) ;

                    ms.Seek(0, SeekOrigin.Begin);

                    if (result.MessageType == WebSocketMessageType.Binary)
                    {
                        using (var reader = new StreamReader(ms, Encoding.UTF8))
                        {
                           // reader.ReadToEnd();
                            txtOutgoing.Text = reader.ReadToEnd();
                        }
                    }
                   // return;
Posted
Updated 5-Jul-18 3:37am
v2
Comments
Sajjid Atta 6-Jul-18 14:14pm    
Hi, Could you please clarify this part "...end of message send..." in your question.

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