Websockets.unitypackage example doesn't work anymore?

I tried this package like 3-4 months ago and it worked fine.
http://files.unity3d.com/jonas/WebSockets.unitypackage

We even had a part of game with websocket working with WebGL for a while. (it was in the Unity5 beta)

Today I checked for a WebGL export, and it just hang in Firefox. I got no error or crash, and the CPU and the memory are changing.

And I found out it seem related to the websocket. I can reproduce the problem only with the websocket example package.

Anyone know why?

I use 5.1.2f1, Firefox 39.0 on Windows 7

which problems do you experience exactly?
i’m using the .jslib from this package without
any real troubles (rewrote some parts on my own thou)

Firefox just hang, no error or crash

any code that’s run? have you tried some print calls to your js-console to debug where it’s happening? which library functions do you call?

I didn’t try to debug directly the jslib, but when I do, I’ll update the post.

I only call that:

public IEnumerator Start()
    {
        Application.logMessageReceived += OnLog;

        WebSocket w = new WebSocket(new Uri("ws://echo.websocket.org"));
        Debug.Log("Trying connect...");
        yield return StartCoroutine(w.Connect());
        Debug.Log("Connected");
        w.SendString("Hi there");
        int i=0;
        while (true)
        {
            string reply = w.RecvString();
            if (reply != null)
            {
                Debug.Log ("Received: "+reply);
                w.SendString("Hi there"+i++);
            }
            if (w.Error != null)
            {
                Debug.LogError ("Error: "+w.Error);
                break;
            }
            yield return 0;

        }
        w.Close();
    }

why do you try to do this endless IEnumerator in start?

simply put your message-handling in the update() and get rid of this while(true) construct… :slight_smile:

my guess is that since the coroutine you fork off in start never finishes unity never gets over the initialization phase, so you’ve basically halted in an endless loop before you even get to the main event loop

You should read about coroutine, it work well. And this code come from the unitypackage from Jonas Echterhoff

1 Like

This appears to have broken in unity 5.1.2. Surprised more people haven’t run into it.

I don’t use the unitypackage in question, however I have the same issue. Essentially, Marshal.FreeHGlobal is crashing. Unfortunately I don’t know of a good fix, other than to not release the memory in question. Hopefully this is fixed with a patch soon.

It looks like this is closed by design… Unity Issue Tracker - [WebGL] socket plugin no longer working

I’m not sure why though, and am pretty annoyed that a breaking change like this was introduced without notice in what appeared to be a small update (between 5.1.1 to 5.1.2 should only really be for bugfixes imo…)

1 Like

Thanks for the info, that’s really bad for us.

FWIW you should be able to replace it with passing strings directly, it’s just annoying that they broke the current way it works.

The old version might not be compatible any more, please make sure you are using the latest from the asset store.

1 Like

My bad, I didn’t know it was on the asset store…

I updated and everything work great.
Thanks!