sta / sta/websocket-sharp

Unable to handle large message size (>2Mb)

Open
#745 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
6.1k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

First of all, thanks for the great library! It works flawlessly for simple stuff and is a great starting point for getting feet wet with WebSockets or when I don't want to deal with all the nitty grittiness on my own. Besides what others say, I haven't run into performance problems so far - probably because I don't have that many client connections at the same time. On the other hand, the lack of proper net standard and .Net core support really makes this library less safe to use because Visual Studio is constantly warning about incompatibility issue.

I have seen quite a few other issues mentioning this issue (https://github.com/sta/websocket-sharp/issues/727, https://github.com/sta/websocket-sharp/issues/702, https://github.com/sta/websocket-sharp/issues/614, https://github.com/sta/websocket-sharp/issues/550, https://github.com/sta/websocket-sharp/issues/332, https://github.com/sta/websocket-sharp/issues/77), but I think I will start my own thread, as a mark for NOT using this library moving forward. At this moment, based on observations of issues above - there are barely any reply whatsoever - I think the original author of this library definitely do not have the capacity to maintain this library further or dealing with any of those mentioned issues. I advise future seekers either participate or contribute to this library, or maybe it's better to move elsewhere and implement their own library.

The key issue I am having right now is the library cannot handle large messages - try below for server and client:

using WebSocketSharp;
using WebSocketSharp.Server;

namespace Server
{
    public class MessageBehavior: WebSocketBehavior
    {
        protected override void OnMessage(MessageEventArgs e)
        {
            // Just echo
            Send(e.Data);
        }
    }

    internal class Program
    {
        static void Main(string[] args)
        {
            var server = new WebSocketServer("ws://localhost:9781");
            server.AddWebSocketService<MessageBehavior>("/Message");
            server.Start();
            Console.ReadKey(true);
            server.Stop();
        }
    }
}
using System.Text;
using WebSocketSharp;

namespace Client
{
    internal class Program
    {
        static void Main(string[] args)
        {
            using var client = new WebSocket("ws://localhost:9781/Message");
            client.OnMessage += OnMessage;
            client.Connect();
            client.Send(GenerateReallyLongMessage());
            Console.ReadKey(true);
        }

        private static string GenerateReallyLongMessage()
        {
            StringBuilder buider = new();
            for (int i = 0; i < 10000; i++)
            {
                buider.Append($"{i}: ");
                for (int j = 0; j < 100; j++)
                    buider.Append($"{j},");
                buider.AppendLine();
            }
            return buider.ToString().TrimEnd();
        }

        private static void OnMessage(object? sender, MessageEventArgs e)
        {
            Console.WriteLine(e.Data);
        }
    }
}

It works well for 1000 but will not work for 10000 iterations, which is around 2Mb text data.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided server and client programs, comparing the 1000-iteration and 10000-iteration messages. Trace the send and echo flow through WebSocket.Send and MessageBehavior.OnMessage to identify where large messages stop being handled. Done means the larger sample completes and is echoed successfully, with an appropriate regression check if the project has one.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.