Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Websockets.unitypackage example doesn't work anymore?

Discussion in 'WebGL' started by DarkPixel, Jul 29, 2015.

  1. DarkPixel

    DarkPixel

    Joined:
    Sep 13, 2013
    Posts:
    79
    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
     
  2. mnml_

    mnml_

    Joined:
    Jun 17, 2015
    Posts:
    44
    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)
     
  3. DarkPixel

    DarkPixel

    Joined:
    Sep 13, 2013
    Posts:
    79
    Firefox just hang, no error or crash
     
  4. mnml_

    mnml_

    Joined:
    Jun 17, 2015
    Posts:
    44
    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?
     
  5. DarkPixel

    DarkPixel

    Joined:
    Sep 13, 2013
    Posts:
    79
    I didn't try to debug directly the jslib, but when I do, I'll update the post.

    I only call that:
    Code (CSharp):
    1.    
    2. public IEnumerator Start()
    3.     {
    4.         Application.logMessageReceived += OnLog;
    5.  
    6.         WebSocket w = new WebSocket(new Uri("ws://echo.websocket.org"));
    7.         Debug.Log("Trying connect...");
    8.         yield return StartCoroutine(w.Connect());
    9.         Debug.Log("Connected");
    10.         w.SendString("Hi there");
    11.         int i=0;
    12.         while (true)
    13.         {
    14.             string reply = w.RecvString();
    15.             if (reply != null)
    16.             {
    17.                 Debug.Log ("Received: "+reply);
    18.                 w.SendString("Hi there"+i++);
    19.             }
    20.             if (w.Error != null)
    21.             {
    22.                 Debug.LogError ("Error: "+w.Error);
    23.                 break;
    24.             }
    25.             yield return 0;
    26.  
    27.         }
    28.         w.Close();
    29.     }
    30.  
     
  6. mnml_

    mnml_

    Joined:
    Jun 17, 2015
    Posts:
    44
    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... :)

    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
     
  7. DarkPixel

    DarkPixel

    Joined:
    Sep 13, 2013
    Posts:
    79
    You should read about coroutine, it work well. And this code come from the unitypackage from Jonas Echterhoff
     
    mnml_ likes this.
  8. muzzythom

    muzzythom

    Joined:
    Dec 1, 2014
    Posts:
    17
    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.
     
  9. muzzythom

    muzzythom

    Joined:
    Dec 1, 2014
    Posts:
    17
    DarkPixel likes this.
  10. DarkPixel

    DarkPixel

    Joined:
    Sep 13, 2013
    Posts:
    79
    Thanks for the info, that's really bad for us.
     
  11. muzzythom

    muzzythom

    Joined:
    Dec 1, 2014
    Posts:
    17
    FWIW you should be able to replace it with passing strings directly, it's just annoying that they broke the current way it works.
     
  12. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    DarkPixel likes this.
  13. DarkPixel

    DarkPixel

    Joined:
    Sep 13, 2013
    Posts:
    79
    My bad, I didn't know it was on the asset store..

    I updated and everything work great.
    Thanks!