Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to handle large message size (>2Mb) #745

Open
chaojian-zhang opened this issue Feb 14, 2024 · 1 comment
Open

Unable to handle large message size (>2Mb) #745

chaojian-zhang opened this issue Feb 14, 2024 · 1 comment

Comments

@chaojian-zhang
Copy link

chaojian-zhang commented Feb 14, 2024

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 (#727, #702, #614, #550, #332, #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.

@CosmicStud
Copy link

CosmicStud commented Feb 14, 2024

It is more so a computer processing limitation. Entirely depends on the server/computer you use. Server level speeds max at about 2.5-10 mbs download/upload on reliable transmissions depending on the server. Unreliable can peak higher but it will cause a huge bottleneck on messages coming in/out... That is also with 20-60 dollar servers on Linode

If you use Unity, you can scale the devices max in/out speeds by the average FPS, for example a mobile device can do at max 1.5-3 mbs per second before bottlenecking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants