sta / websocket-sharp

A C# implementation of the WebSocket protocol client and server
http://sta.github.io/websocket-sharp
MIT License
5.68k stars 1.66k forks source link

Uncaught RangeError: Maximum call stack size exceeded (Unity 5.1 -> HTML5 (webGL)) #139

Open devMidgard opened 9 years ago

devMidgard commented 9 years ago

Hello there, I've begun to work with WebSockets in C# with this nice plugin thing but I can't seem to get it working, I have a WebSocket Server made in a console application which is working nice, and if I start the client from the Unity Editor it works just fine, it's only when I export to HTML5 (WebGL) that it pops up me an error as soon as the game has loaded.

This is the log:

Invoking error handler due to Uncaught RangeError: Maximum call stack size exceeded

And this is my client code:

using UnityEngine; using System.Collections; using System; using WebSocketSharp;

public class NetworkHandler : MonoBehaviour {

IEnumerator Start()
{
    WebSocket ws = new WebSocket("ws://127.0.0.1:9090/server");

    ws.OnMessage += OnReceivedMessage;
    ws.OnOpen += OnOpened;

    ws.Connect();
    yield return new WaitForSeconds(1);
    ws.Send("Client saying hi");
}

public void OnReceivedMessage(object sender, MessageEventArgs e)
{
    Debug.Log("Server says: " + e.Data);
}

public void OnOpened(object sender, EventArgs e)
{
    Debug.Log("Established Connection with a Game Server!");
}

}

Please let me know what am I doing wrong, or if this is something I can't really fix so I can move on!

Thankyu beforehand

sta commented 9 years ago

Hello there,

Did you build it as a WebGL app?

I've heard Unity WebGL doesn't support .NET Socket. If so, i guess it's impossible to use websocket-sharp in WebGL apps project.

See also: WebGL Networking

devMidgard commented 9 years ago

Hi, as you can see in the same page:

" However, if you need networking capabilities beyond the WWW class, it is possible to use Web Sockets or WebRTC, both networking protocols supported by browsers."

Apparently it should support Web Sockets, but what's the difference between .NET WebSockets and others? I am pretty new on every single thing regarding websockets.. Sorry if this sounds stupid, but I'd like a full explanation!

Cheers

2015-06-23 5:07 GMT+02:00 sta notifications@github.com:

Hello there,

Did you build it as a WebGL app?

I've heard Unity WebGL doesn't support .NET Socket. If so, i guess it's impossible to use websocket-sharp in WebGL apps project.

See also: WebGL Networking http://docs.unity3d.com/Manual/webgl-networking.html

— Reply to this email directly or view it on GitHub https://github.com/sta/websocket-sharp/issues/139#issuecomment-114338444 .

sta commented 9 years ago

However, if you need networking capabilities beyond the WWW class, it is possible to use Web Sockets or WebRTC, both networking protocols supported by browsers.

I think that means it's possible to use WebSocket or WebRTC built in the browsers.

There is no WebSocket module to use in every programing language, but there are some WebSocket protocol implementations in each programing language.

websocket-sharp is written in C#, and based on .NET Socket, but has no relation with WebSocket built in the browsers.

songololo commented 9 years ago

Unity provides a template plugin (also available from the app store) that will use a javascript web socket implementation when running in WebGL, but otherwise if using a non-web application, then it defaults to the C# web socket sharp implementation.

I believe that it is discussed on this page, but I can't get the page to load at the moment: WebGL roadmap

Here is the app store link.

ntalamdotcom commented 2 years ago

2021, I am still getting that error, not using websocket