public void Close()
    {
        Debug.Log("[UnityWebSocket] Closing web socket connection.");

#if UNITY_EDITOR || UNITY_STANDALONE
        if (WebSocket == null)
        {
            return;
        }
        WebSocket.CloseAsync();
        WebSocket.OnOpen    -= WebSocket_OnOpen;
        WebSocket.OnMessage -= WebSocket_OnMessage;
        WebSocket.OnError   -= WebSocket_OnError;
        WebSocket.OnClose   -= WebSocket_OnClose;
        WebSocket            = null;
#elif UNITY_WEBGL
        if (NativeWebSocket == null)
        {
            return;
        }
        NativeWebSocket.CloseAsync();
        NativeWebSocket.SetOnOpen(null);
        NativeWebSocket.SetOnMessage(null);
        NativeWebSocket.SetOnError(null);
        NativeWebSocket.SetOnClose(null);
        NativeWebSocket = null;
#endif
    }
Beispiel #2
0
        public void Close()
        {
#if DOT_NET
            if (ClientWebSocket == null)
            {
                return;
            }
            ClientWebSocket.CloseAsync(WebSocketCloseStatus.Empty, null, CancellationToken.None);
            ClientWebSocket = null;
#elif UNITY_WEBGL && !UNITY_EDITOR
            if (NativeWebSocket == null)
            {
                return;
            }
            webSocketInstances.Remove(NativeWebSocket.Id);
            NativeWebSocket.CloseAsync();
            NativeWebSocket = null;
#else
            if (WebSocket == null)
            {
                return;
            }
            WebSocket.CloseAsync();
            WebSocket.OnOpen    -= WebSocket_OnOpen;
            WebSocket.OnMessage -= WebSocket_OnMessage;
            WebSocket.OnError   -= WebSocket_OnError;
            WebSocket.OnClose   -= WebSocket_OnClose;
            WebSocket            = null;
#endif
        }
Beispiel #3
0
        /// <summary>
        /// Creates the native websocket instance.
        /// </summary>
        /// <param name="assemblyPath">The assembly path.</param>
        /// <param name="assemblyIdentifier">The assembly identifier.</param>
        /// <param name="websocketPort">The websocket port.</param>
        private static void createNativeWebsocketInstance(int websocketPort)
        {
            Instance = new ProcessLocal();

            port = websocketPort;

            nws = new NativeWebSocket(port);
        }
Beispiel #4
0
 /// <summary>
 /// Construct socketIO client with given configuration
 /// </summary>
 /// <param name="config"></param>
 public SocketIO(SocketIOConfigurator config, MonoBehaviour scriptInstance = null) :
     base(config)
 {
     if (Application.platform == RuntimePlatform.WebGLPlayer)
     {
         Socket = new WebGLWebSocket(scriptInstance);
     }
     else
     {
         Socket = new NativeWebSocket(config.Proxy, config.ConnectTimeout);
     }
 }
    public BrainCloudWebSocket(string url)
    {
#if DOT_NET
#elif UNITY_WEBGL && !UNITY_EDITOR
        NativeWebSocket = new NativeWebSocket(url);
        NativeWebSocket.SetOnOpen(NativeSocket_OnOpen);
        NativeWebSocket.SetOnMessage(NativeSocket_OnMessage);
        NativeWebSocket.SetOnError(NativeSocket_OnError);
        NativeWebSocket.SetOnClose(NativeSocket_OnClose);
        webSocketInstances.Add(NativeWebSocket.Id, this);
#else
        WebSocket = new WebSocket(url);
        WebSocket.ConnectAsync();
        WebSocket.OnOpen    += WebSocket_OnOpen;
        WebSocket.OnMessage += WebSocket_OnMessage;
        WebSocket.OnError   += WebSocket_OnError;
        WebSocket.OnClose   += WebSocket_OnClose;
#endif
    }
    public UnityWebSocket(string url)
    {
        Debug.Log("[UnityWebSocket] Instantiating new websocket: " + url);

#if UNITY_EDITOR || UNITY_STANDALONE
        WebSocket = new WebSocket(url);
        WebSocket.ConnectAsync();
        WebSocket.AcceptAsync();
        WebSocket.OnOpen    += WebSocket_OnOpen;
        WebSocket.OnMessage += WebSocket_OnMessage;
        WebSocket.OnError   += WebSocket_OnError;
        WebSocket.OnClose   += WebSocket_OnClose;
#elif UNITY_WEBGL
        NativeWebSocket = new NativeWebSocket(url);
        NativeWebSocket.SetOnOpen(NativeSocket_OnOpen);
        NativeWebSocket.SetOnMessage(NativeSocket_OnMessage);
        NativeWebSocket.SetOnError(NativeSocket_OnError);
        NativeWebSocket.SetOnClose(NativeSocket_OnClose);
        webSocketInstances.Add(NativeWebSocket.Id, this);
#endif
    }
    public void Close()
    {
#if DOT_NET
#elif UNITY_WEBGL && !UNITY_EDITOR
        if (NativeWebSocket == null)
        {
            return;
        }
        webSocketInstances.Remove(NativeWebSocket.Id);
        NativeWebSocket.CloseAsync();
        NativeWebSocket = null;
#else
        if (WebSocket == null)
        {
            return;
        }
        WebSocket.CloseAsync();
        WebSocket.OnOpen    -= WebSocket_OnOpen;
        WebSocket.OnMessage -= WebSocket_OnMessage;
        WebSocket.OnError   -= WebSocket_OnError;
        WebSocket.OnClose   -= WebSocket_OnClose;
        WebSocket            = null;
#endif
    }
Beispiel #8
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(NativeWebSocket obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Beispiel #9
0
 public SocketIO(SocketIOConfigurator config) :
     base(config)
 {
     Socket = new NativeWebSocket(config.Proxy);
 }
Beispiel #10
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(NativeWebSocket obj)
 {
     return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
 }
Beispiel #11
0
 /// <summary>
 /// Construct socketIO client with given configuration
 /// </summary>
 /// <param name="config"></param>
 public SocketIO(SocketIOConfigurator config) :
     base(config)
 {
     Socket = new NativeWebSocket(config.Proxy, config.ConnectTimeout);
 }
Beispiel #12
0
 public static void LogMessage(string Message, NativeWebSocket WebSocketInstance)
 {
     FileLogger.Instance.LogMessage(Message);
     WebSocketInstance.SendLogMessage(WebSocket.LogMessageType.FatalStreamMessage.ToString(), Message, "");
 }