示例#1
0
 protected override void SendImpl(string json)
 {
     if (wSocket != null && wSocket.IsOpen)
     {
         wSocket.Send(json);
     }
 }
        protected override void SendImpl(string json)
        {
#if UNITY_EDITOR
            if (!string.IsNullOrEmpty(json))
            {
                VKDebug.Log(json, VKCommon.HEX_ORANGE);
            }
#endif

            if (wSocket != null && wSocket.IsOpen)
            {
                wSocket.Send(json);
            }
        }
示例#3
0
        void OnGUI()
        {
            GUIHelper.DrawArea(GUIHelper.ClientArea, true, () =>
            {
                scrollPos = GUILayout.BeginScrollView(scrollPos);
                GUILayout.Label(Text);
                GUILayout.EndScrollView();

                GUILayout.Space(5);

                GUILayout.FlexibleSpace();

                address = GUILayout.TextField(address);

                if (webSocket == null && GUILayout.Button("Open Web Socket"))
                {
                    // Create the WebSocket instance
                    webSocket = new WebSocket.WebSocket(new Uri(address));

#if !UNITY_WEBGL
                    webSocket.StartPingThread = true;

#if !BESTHTTP_DISABLE_PROXY
                    if (HTTPManager.Proxy != null)
                    {
                        webSocket.InternalRequest.Proxy = new HTTPProxy(HTTPManager.Proxy.Address, HTTPManager.Proxy.Credentials, false);
                    }
#endif
#endif

                    // Subscribe to the WS events
                    webSocket.OnOpen    += OnOpen;
                    webSocket.OnMessage += OnMessageReceived;
                    webSocket.OnClosed  += OnClosed;
                    webSocket.OnError   += OnError;

                    // Start connecting to the server
                    webSocket.Open();

                    Text += "Opening Web Socket...\n";
                }

                if (webSocket != null && webSocket.IsOpen)
                {
                    GUILayout.Space(10);

                    GUILayout.BeginHorizontal();
                    msgToSend = GUILayout.TextField(msgToSend);

                    GUILayout.EndHorizontal();

                    if (GUILayout.Button("Send", GUILayout.MaxWidth(70)))
                    {
                        Text += "Sending message...\n";

                        // Send message to the server
                        webSocket.Send(msgToSend);
                    }

                    GUILayout.Space(10);

                    if (GUILayout.Button("Close"))
                    {
                        // Close the connection
                        webSocket.Close(1000, "Bye!");
                    }
                }
            });
        }