コード例 #1
0
        protected void ConnectWebSocket()
        {
            if (string.IsNullOrEmpty(FTLSocketUri))
            {
                Debug.LogError("FTL SocketUri must be set");
                return;
            }

            var customHeaders = new List <KeyValuePair <string, string> >();

            if (Headers != null)
            {
                foreach (UnityKeyValue header in Headers)
                {
                    customHeaders.Add(new KeyValuePair <string, string>(header.key, header.value));
                }
            }

#if ENABLE_WINMD_SUPPORT
            Debug.Log("Using UWP Web Socket");
            _ws = new WebSocketUWP();
#elif UNITY_EDITOR || ENABLE_MONO
            Debug.Log("Using Mono FTL Socket");
            _ws = new WebSocketMono();
#endif

            if (!isAttached)
            {
                _ws.ConfigureWebSocket(FTLSocketUri, customHeaders);
                Debug.Log("Connect FTL Socket: " + _ws.Url());
                AttachHandlers();
                _ws.ConnectAsync();
            }
        }