Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  6. Unity 2017.2 beta is now available for download.
    Dismiss Notice

Unity5 Beta : WebGL + Unity WebSockets plug-in

Discussion in 'Unity 5 Pre-order Beta' started by peter_on, Nov 1, 2014.

  1. peter_on

    peter_on

    Joined:
    Jan 8, 2009
    Posts:
    63
    Hi,

    Quote : http://blogs.unity3d.com/2014/04/29/on-the-future-of-web-publishing-in-unity/
    "WebGL in Unity 5.0
    We plan to WebGL support available in Unity 5.0 as an early-access add-on. Early-Access means that it will be capable of publishing content to WebGL (like the examples above), but it will have some limitations in features and in browser compatibility. In particular, the following features will not be supported:
    • Networking other then WWW class (a WebSockets plug-in is available)"
    I'm searching for websockets plugin in unity5.0.9beta. Could unity shed some lights on the unity websockets plugin availability in unity5 ? thank you!

    Br,
    Peter
     
    Last edited: Nov 1, 2014
    Blarp and Xaurrien like this.
  2. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    60
    Bump
     
  3. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,479
    sonxoans2, Nik0s and Blarp like this.
  4. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,282
    There's also an example of using Socket.IO with WebGL:
     
    Blarp likes this.
  5. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    60
    Thanks jonas!

    My project is recreating an MMO via Unity WebGL (for the client). We already have existing server-side code thats been around for 12 years.

    This is our implementation for exposing the Server to Websockets so we can communicate with the client: http://wiki.eqemulator.org/p?Project_Web_Sockets

    This is the complete serverside code: https://github.com/EQEmu/Server/tree/web_interface
     
    Dustin-Horne likes this.
  6. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,479
    I did not look into your implementation, but just in case people are interested: Websockify is a great tool when you need websockets client to connect to existing IP services (by implementing a bridge from WebSockets <-> IP). We use the same for the profiler connection to the unity editor in WebGL.

    https://github.com/kanaka/websockify
     
    Blarp and Dustin-Horne like this.
  7. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    60
    hey Jonas, let's say I want to add a protocol to the end of the Host url in EchoTest.cs. How would I go about this?

    The Build:
    http://files.unity3d.com/jonas/WebSockets.unitypackage

    The example -
    Host: 38.103.160.13:9080
    Sec-WebSocket-Protocol: eqemu

    Thus making line 9 in EchoTest.cs look something like this:
    WebSocket w = new WebSocket(new Uri("ws://38.103.160.13:9080", "eqemu"));

     
    Last edited: Jan 13, 2015
  8. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,479
    Look at how the code passes the url to JavaScript in the constructor. You should be able to do the same for a protocol.
     
    Blarp likes this.
  9. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    60
    I assume you are talking about line 121 in particular (also lines 13-17) of WebSocket.cs in the WebSockets.unitypackage i linked above.

    http://hastebin.com/wojubibigu.coffee

    Could use some additional assistance if anyone with time could chime in.


    Also, fun fact, this thread is in the top 25 of the total 849 threads in terms of viewer popularity in the Unity 5 pre-order sub forum.
     
  10. bsterling250DI

    bsterling250DI

    Joined:
    Sep 25, 2014
    Posts:
    58
    ya, I've been talking briefly with Photon's Tobias about their early access WebGL support and its a slow process, don't think they have much support right now either.
     
  11. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    60
    Figured out my problem. This is how you add a protocol to the WebSocket package. Might be helpful for someone in the future.

    line 121:
    http://hastebin.com/yesuvazoyi.coffee

    change:
    m_Socket = new WebSocketSharp.WebSocket(mUrl.ToString());

    to:
    m_Socket = new WebSocketSharp.WebSocket(mUrl.ToString(),"eqemu");

    My result:
    [​IMG]
     
  12. yunspace

    yunspace

    Joined:
    Nov 8, 2010
    Posts:
    41
    Blarp likes this.
  13. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    210
    Did someone manage to get plugin working for WebGL build?
    It works fine in Editor(EchoTest), but if I build for WebGL I get:
    Unity 5 b21
     
  14. Onsterion

    Onsterion

    Joined:
    Feb 21, 2014
    Posts:
    171
    Any idea a library for unity 5 WebGL + NodeJS + socket.io?
     
  15. Onsterion

    Onsterion

    Joined:
    Feb 21, 2014
    Posts:
    171
    Well I use directly socket.io from html javascript and works fine.
     
    yunspace likes this.
  16. Nik0s

    Nik0s

    Joined:
    Aug 16, 2013
    Posts:
    9
    Hi! I get the same error as ortin above when testing the Echotest WebGL build in localhost (Unity 5 b20) - any help would be much appreciated:

    Code (CSharp):
    1. Error during WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received
    2. WebSocket is already in CLOSING or CLOSED state.
    3. Error: Abnormal disconnection.
    thanks
     
  17. Nik0s

    Nik0s

    Joined:
    Aug 16, 2013
    Posts:
    9
    To fix edit Assets\Plugins\WebSocket.jslib and in line #9 replace

    Code (CSharp):
    1. socket: new WebSocket(str, ['soap', 'xmpp']),
    with

    Code (CSharp):
    1. socket: new WebSocket(str),
     
  18. yunspace

    yunspace

    Joined:
    Nov 8, 2010
    Posts:
    41
    I found another socket io C# implementation: https://github.com/Quobject/SocketIoClientDotNet which is a direct port from the javascript client and supports SocketIO 1.0.

    But then as @Osterion mentioned, for WebGL builds it could be just easier to use the javascript client right? Is there any value in using C# and then converting it back into JS?
     
  19. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,282
    I don't think you cam use socket connections from within unity webgl. So by JavaScript, I think you need to use actual JavaScript on your host page and proxy between webgl and the JavaScript. So c# would be out as well, at least as far as directly utilizing websockets.