示例#1
1
        private JsonWebSocket CreateWebSocket(ServerConfig config)
        {
            var websocket = new JsonWebSocket(string.Format("ws://{0}:{1}/", config.Host, config.Port), "ServerManager");
#if SILVERLIGHT
            websocket.Opened += new EventHandler(CreateAsyncOperation<object, EventArgs>(m_WebSocket_Opened));
            websocket.Error += new EventHandler<ClientEngine.ErrorEventArgs>(CreateAsyncOperation<object, ClientEngine.ErrorEventArgs>(m_WebSocket_Error));
            websocket.Closed += new EventHandler(CreateAsyncOperation<object, EventArgs>(m_WebSocket_Closed));
            websocket.On<ServerInfo>(CommandName.UPDATE, CreateAsyncOperation<ServerInfo>(OnServerUpdated));
#else
            websocket.Opened += new EventHandler(m_WebSocket_Opened);
            websocket.Error += new EventHandler<ClientEngine.ErrorEventArgs>(m_WebSocket_Error);
            websocket.Closed += new EventHandler(m_WebSocket_Closed);
            websocket.On<ServerInfo>(CommandName.UPDATE, OnServerUpdated);
#endif

            websocket.Open();
            State = ConnectionState.Connecting;
            m_ErrorPopped = false;

            foreach (var instance in Instances)
            {
                instance.State = InstanceState.Connecting;
            }

            return websocket;
        }
示例#2
0
        private void ReconnectTimerCallback(object state)
        {
            //Already connected or started connecting
            if (m_WebSocket != null)
                return;

            m_WebSocket = CreateWebSocket(m_ServerConfig);
        }
示例#3
0
        public ServerViewModel(ServerConfig config)
        {
            Instances = new List<InstanceViewModel>();
            m_ServerConfig = config;
            Name = config.Name;
            m_WebSocket = CreateWebSocket(config);
            m_ReconnectTimer = new Timer(ReconnectTimerCallback, null, Timeout.Infinite, Timeout.Infinite);

            ConfigCommand = new RelayCommand<object>(ExecuteConfigCommand);
        }
示例#4
0
 static JsonWebSocket CreateWebSocket()
 {
     var websocket = new JsonWebSocket("ws://127.0.0.1:2011/");
     
     websocket.On<string>("ECHO", HandleEchoResponse);
     websocket.Closed += new EventHandler(websocket_Closed);
     websocket.Error += new EventHandler<SuperSocket.ClientEngine.ErrorEventArgs>(websocket_Error);
     websocket.Opened += new EventHandler(websocket_Opened);
     websocket.Open();
     return websocket;
 }
示例#5
0
文件: Program.cs 项目: xxjeng/nuxleus
        private static void HandleEchoResponse(JsonWebSocket websocket, string content)
        {
            Interlocked.Increment(ref m_Received);

            if (m_Stopped)
            {
                websocket.Close();
                return;
            }

            RunTest(websocket);
        }
示例#6
0
文件: Program.cs 项目: xxjeng/nuxleus
        static void Main(string[] args)
        {
            var websocket = new JsonWebSocket("ws://127.0.0.1:2011/");

            websocket.On<string>("ECHO", HandleEchoResponse);
            websocket.Closed += new EventHandler(websocket_Closed);
            websocket.Error += new EventHandler<SuperSocket.ClientEngine.ErrorEventArgs>(websocket_Error);
            websocket.Opened += new EventHandler(websocket_Opened);
            websocket.Open();

            m_PrintTimer = new Timer(OnPrintTimerCallback, null, 1000 * 5, 1000 * 5);

            while (!Console.ReadLine().ToLower().Equals("q"))
                continue;

            m_Stopped = true;
            m_PrintTimer.Change(Timeout.Infinite, Timeout.Infinite);

            m_ClosedEvent.WaitOne();

            Console.WriteLine("Quit");
            Console.ReadLine();
        }
示例#7
0
 public override void Execute(JsonWebSocket websocket, string token, object param)
 {
     m_ExecutorActionFull.Method.Invoke(m_ExecutorActionFull.Target, new object[] { websocket, token, param });
 }
示例#8
0
 public abstract void Execute(JsonWebSocket websocket, string token, object param);
示例#9
0
        void m_WebSocket_Error(object sender, ErrorEventArgs e)
        {
            if (State == ConnectionState.Connecting)
            {
                m_WebSocket = null;
                WaitingReconnect();
            }

            if (!m_ErrorPopped)
            {
                m_ErrorPopped = true;
                Messenger.Default.Send<ErrorEventArgs>(e);
            }
        }
示例#10
0
 void m_WebSocketRefresh_Closed(object sender, EventArgs e)
 {
     SetClosedStatus();
     m_WebSocket = CreateWebSocket(m_ServerConfig);
 }
示例#11
0
        void SetClosedStatus(ConnectionState closeState)
        {
            State = closeState;
            m_WebSocket = null;

            foreach (var instance in Instances)
            {
                instance.IsRunning = false;
                instance.State = InstanceState.NotConnected;
            }
        }
示例#12
0
        internal void RefreshConfig()
        {
            this.Name = m_ServerConfig.Name;

            if (m_WebSocket != null)
            {
                m_WebSocket.Closed -= m_WebSocket_Closed;
                m_WebSocket.Closed += new EventHandler(m_WebSocketRefresh_Closed);
                m_WebSocket.Close();
            }
            else
            {
                m_WebSocket = CreateWebSocket(m_ServerConfig);
            }
        }
示例#13
0
 private static void RunTest(JsonWebSocket websocket)
 {
     websocket.Send("ECHO", Guid.NewGuid().ToString() + Guid.NewGuid().ToString() + Guid.NewGuid().ToString() + Guid.NewGuid().ToString());
     Interlocked.Increment(ref m_Sent);
 }
示例#14
0
        internal void RefreshConfig()
        {
            this.Name = m_ServerConfig.Name;

            if (m_WebSocket != null)
            {
                m_WebSocket.Closed -= m_WebSocket_Closed;
#if SILVERLIGHT
                m_WebSocket.Closed += new EventHandler(CreateAsyncOperation<object, EventArgs>(m_WebSocketRefresh_Closed));
#else
                m_WebSocket.Closed += new EventHandler(m_WebSocketRefresh_Closed);
#endif
                m_WebSocket.Close();
            }
            else
            {
                m_WebSocket = CreateWebSocket(m_ServerConfig);
            }
        }
示例#15
0
        private static void RunTest(JsonWebSocket websocket)
        {
            websocket.Send("ECHOX", new ClientInfo
            {
                ID = m_Random.Next(1, 1000),
                Height = m_Random.Next(1, 1000),
                LocationX = m_Random.Next(1, 1000),
                LocationY = m_Random.Next(1, 1000)
            });

            Interlocked.Increment(ref m_Sent);
        }