示例#1
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Destroy(gameObject);
     }
 }
示例#2
0
 void Awake()
 {
     if(instance == null)
     {
         instance = this;
     }
     else
     {
         Destroy (gameObject);
     }
 }
示例#3
0
 public void Stop()
 {
     if (SocketBase != null)
     {
         threadReConnect.Abort();
         threadReConnect = null;
         RemoveChannel();
         SocketBase.stop();
         SocketBase    = null;
         SocketService = null;
     }
 }
示例#4
0
        public static async Task DistributeAsync(HttpContext context, Type t)
        {
            var webSocket = await context.WebSockets.AcceptWebSocketAsync();

            IWebSocket i_webSocket = new WebSocketImpl(webSocket);
            object     instance    = Activator.CreateInstance(t, new object[] { i_webSocket });

            i_webSocket.AddClient(i_webSocket);

            //t.GetMethod("Connect")?.Invoke(instance, new Object[] { context, null });

            await Echo(context, webSocket, i_webSocket, instance, t);

            try
            {
                i_webSocket.RemoveClient(i_webSocket);
            }
            catch (Exception)
            {
            }

            // IWebSocket iwebsocket = new WebSocketImpl(webSocket);

            // JObject recv_data = iwebsocket.ReceiveAsync();

            // Assembly assembly = Assembly.Load(ass);
            // MethodInfo method = null;
            // try
            // {
            //     //assembly.GetTypes().Select(s=>s.GetMethods()).Where(w=>w.GetCustomAttribute(typeof(SocketRouteAttribute)) != null)
            //     method = assembly
            //     .GetTypes()
            //     .SelectMany(s => s.GetMethods())
            //     .First(f => f
            //         .GetCustomAttributes(typeof(SocketRouteAttribute), false)
            //         .Any(w => ((SocketRouteAttribute)w).Path == recv_data["target"].ToString()));

            //     if (!context.WebSockets.IsWebSocketRequest || method == null)
            //         context.Response.StatusCode = 404;

            //     object socketProsess = Activator.CreateInstance(tySocket, new object[] { iwebsocket });
            //     method.Invoke(socketProsess, new object[] { context.Request, recv_data });
            // }
            // catch (Exception)
            // {
            //     iwebsocket.SendAsync(new Result(400, "请求错误"));
            // }
        }
示例#5
0
        public void Start()
        {
            if (SocketBase == null)
            {
                SocketService = new WebSocketImpl();
                SocketBase    = new  WebSocketBaseOKCoin(SelectedUrl, SocketService as WebSocketService);
                SocketBase.start();

                //var dict = new Dictionary<string, string>();
                //dict.Add("api_key", ConfigInfo.apiKey);
                //wsb.send("{\"event\":\"login\",\"parameters\":{\"api_key\":\"" + ConfigInfo.apiKey + "\",\"sign\":\"" + SignParams(dict) + "\"}}");//登录

                threadReConnect = new Thread(new ThreadStart(Reconnect))
                {
                    IsBackground = true
                };
                threadReConnect.Start();
            }
        }
 public static void SetWriteableCallback(this WebSocketImpl webSocket, Action onWriteable)
 {
     webSocket.SetWriteableCallback(new WritableCallback(onWriteable));
 }
 public static void SetEndCallback(this WebSocketImpl webSocket, Action <Exception> onCompleted)
 {
     webSocket.SetEndCallback(new CompletedCallback(onCompleted));
 }
 public static void SetDataCallback(this WebSocketImpl webSocket, Action <IDataEmitter, ByteBufferList> onDataAvailable)
 {
     webSocket.SetDataCallback(new WebSocketDataCallback(onDataAvailable));
 }