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

Unity3D and websockets

Discussion in 'Editor & General Support' started by zukias, Jan 3, 2020.

  1. zukias

    zukias

    Joined:
    Oct 18, 2017
    Posts:
    5
    I have been trying to find info on websockets in unity3d, but everywhere I can find a mention of it on the unity3D docs are dead links, or it says it is deprecated, without giving an alternative, so am wondering if any good Samaritans out there could give me an overview on current websocket support in Unity3D? :)

    I would like to be able to use the standard browser's window.WebSocket in html5, and whatever is available in android and iOS
     
  2. novabyte

    novabyte

    Joined:
    Feb 27, 2015
    Posts:
    12
    Hey @zukias I can help. Most of the WebSocket libraries have been deprecated or have become dead links because support for .NET4.6 in Unity enables the use of the standard library WebSocket implementation. This does not work on HTML5 builds though so you'll need a small shim for that build target.

    We don't use the
    System.Net.WebSocket
    namespace in Nakama for a few different reasons (all are due to bugs in Unity):
    • IPv4 address is not tried correctly if the IPv6 address fails to resolve; it's a problem in
      TcpClient
      .
    • The WebSocket will always fail to respond to frame control messages (i.e. PINGs) after 300 seconds.
    Instead we use this reimplementation of the standard library WebSockets as a standalone library:

    https://github.com/ninjasource/Ninja.WebSockets

    You can find the small shim we use for HTML5 builds on our open-source code repo:

    https://github.com/heroiclabs/nakam...s/Nakama/Plugins/UnityWebGLSocketBridge.jslib

    Hope this helps.
     
    Last edited: Jan 3, 2020