コード例 #1
0
 void IObservable <ClientConnectedArgs> .Notify(ClientConnectedArgs eventArgs)
 {
     if (_clientConnected != null)
     {
         _clientConnected.Invoke(this, eventArgs);
     }
 }
コード例 #2
0
 void IObservable <ClientConnectedArgs> .Notify(ClientConnectedArgs eventArgs)
 {
     if (ConnectedToHost != null)
     {
         ConnectedToHost.Invoke(this, eventArgs);
     }
 }
コード例 #3
0
ファイル: DiscordServer.cs プロジェクト: rafal06/Quarrel
 private void Server_ClientConnected(object sender, ClientConnectedArgs e)
 {
     Console.ForegroundColor = ConsoleColor.Green;
     Console.WriteLine("Client connected");
     Console.ForegroundColor = ConsoleColor.White;
     ConnectionUpdate(null, ConnectionState.Connected);
 }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: yhtsnda/aaasoft
        void xsServer_ClientConnected(object sender, ClientConnectedArgs e)
        {
            var          dict         = new Dictionary <string, string>();
            EventPackage eventPackage = new EventPackage("Welcome");

            eventPackage.AddArgument("NowTime", DateTime.Now.ToString());
            e.setEventPackage(eventPackage);
        }
コード例 #5
0
        void IObserver <ClientConnectedArgs> .OnNotified(object sender, ClientConnectedArgs eventArgs)
        {
            if (ConnectedToHost != null)
            {
                ConnectedToHost.Invoke(this, eventArgs);
            }

            _stateController.SwitchState(StateType.GamePadState);
        }
コード例 #6
0
        public NetworkController()
        {
            _networkStrategy = NetworkStrategyFactory.Instance.CreateDotNetworkStrategy();

//#if NETFX_CORE
//            _networkStrategy = NetworkStrategyFactory.Instance.CreateUWPworkStrategy();
//#else
//            _networkStrategy = NetworkStrategyFactory.Instance.CreateDotNetworkStrategy();
//#endif
            ListenerStartedArgs = new ListenerStartedArgs();
            ClientConnectedArgs = new ClientConnectedArgs();
        }
コード例 #7
0
ファイル: MinerServer.cs プロジェクト: minernl/MinerProxy2
        private void MinerServer_OnClientConnected(object sender, ClientConnectedArgs e)
        {
            string remoteAddress = e.connection.endPoint.Address.ToString();

            if (_poolClient.allowedIPAddresses.Count > 0 && !_poolClient.allowedIPAddresses.Contains("0.0.0.0"))
            {
                if (!_poolClient.allowedIPAddresses.Contains(remoteAddress))
                {
                    Log.Warning("Connection from {0} not allowed; ignoring", remoteAddress);
                    minerServer.Disconnect(e.connection);
                    return;
                }
            }

            _poolClient.IsPoolConnectionRequired();
            Log.Debug("[{0}] new connection from {1}", _poolClient.poolWorkerName, e.connection.endPoint.ToString(), _poolClient.poolWorkerName);
            _coinHandler.MinerConnected(e.connection);
        }
コード例 #8
0
ファイル: ServerControl.cs プロジェクト: jackizhang/Chat
        private void UpdateClientConnected(object state)
        {
            ClientConnectedArgs args = state as ClientConnectedArgs;

            //if some clients are already connected
            if (lstClients.Items.Count > 0)
            {
                //let's see if the connected client is a returning customer
                foreach (ListViewItem clientRecord in lstClients.Items)
                {
                    if (clientRecord.Text == args.UserName)
                    {
                        //update connection status
                        clientRecord.SubItems[1].Text = "Connected";
                    }
                    else
                    {
                        //a client is completely new - add a new Client record
                        ListViewItem newClientRecord = new ListViewItem {
                            Text = args.UserName
                        };
                        newClientRecord.SubItems.Add("Connected");
                        newClientRecord.SubItems.Add(args.ConnectionTime.ToShortTimeString());
                        //newClientRecord.SubItems.Add(args.Id);
                        lstClients.Items.Add(newClientRecord);
                        tabMain.SelectedTab = tabClients;
                    }
                }
            }
            else
            {
                //First client - create a ListViewItem
                ListViewItem newClientRecord = new ListViewItem {
                    Text = args.UserName
                };
                newClientRecord.SubItems.Add("Connected");
                newClientRecord.SubItems.Add(args.ConnectionTime.ToShortTimeString());
                //newClientRecord.SubItems.Add(args.Id);
                lstClients.Items.Add(newClientRecord);
                tabMain.SelectedTab = tabClients;
            }
        }
コード例 #9
0
 void IObserver <ClientConnectedArgs> .OnNotified(object sender, ClientConnectedArgs eventArgs)
 {
     (this as IObservable <ClientConnectedArgs>).Notify(eventArgs);
 }
コード例 #10
0
        private void receiveRequestThreadFunction(Object obj)
        {
            Socket socket = (Socket)obj;

            IPEndPoint ipep = (IPEndPoint)socket.RemoteEndPoint;
            //连接的IP地址
            IPAddress remoteInetAddress = ipep.Address;
            int       remotePort        = ipep.Port;

            //客户端连接信息参数对象
            ClientConnectionInfoArgs clientConnectionInfoArgs = new ClientConnectionInfoArgs(socket, remoteInetAddress, remotePort);

            //是否在发送完响应后断开连接
            Boolean isDisconnectWhenSendResponseFinish = false;

            pushLog(String.Format("{0}:{1} 连接到服务器。", remoteInetAddress, remotePort));
            try
            {
                //设置接受超时时间
                socket.ReceiveTimeout = _heartBeatTimeout * 1000;
                NetworkStream networkStream = new NetworkStream(socket);

                ClientConnectedArgs clientConnectedArgs = new ClientConnectedArgs(clientConnectionInfoArgs);
                //触发客户端连接事件
                if (this.ClientConnected != null)
                {
                    ClientConnected.Invoke(this, clientConnectedArgs);
                }

                if (!clientConnectedArgs.getIsAccept())
                {
                    throw new Exception("此连接不被接受,已断开。");
                }
                if (clientConnectedArgs.getEventPackage() != null)
                {
                    XiepIoHelper.SendPackage(networkStream, clientConnectedArgs.getEventPackage());
                }
                while (true)
                {
                    //接收请求包的XML字符串
                    String xml = XiepIoHelper.ReceiveXml(networkStream);
                    if (xml == null)
                    {
                        throw new IOException("获取数据包字符串失败。");
                    }
                    //请求包
                    RequestPackage requestPackage = RequestPackage.fromXml(xml);
                    if (requestPackage == null)
                    {
                        throw new IOException("字符串转换为请求数据包时失败。");
                    }
                    //响应包
                    ResponsePackage responsePackage = null;

                    String requestName = requestPackage.Request;
                    //如果找到了对应的处理器
                    if (this._requestHandlerMap.ContainsKey(requestName))
                    {
                        responsePackage = this._requestHandlerMap[requestName].execute(clientConnectionInfoArgs, requestPackage);
                    }
                    //如果是客户端发来的心跳消息包
                    if (requestPackage.Request.Equals("XiepPing"))
                    {
                    }
                    else
                    {
                        ReceiveRequestArgs receiveRequestArgs = new ReceiveRequestArgs(clientConnectionInfoArgs, requestPackage);
                        receiveRequestArgs.setResponsePackage(responsePackage);
                        //触发接收到客户端请求事件
                        if (ReceiveRequest != null)
                        {
                            ReceiveRequest.Invoke(this, receiveRequestArgs);
                        }

                        responsePackage = receiveRequestArgs.getResponsePackage();
                        isDisconnectWhenSendResponseFinish = receiveRequestArgs.getIsDisconnectWhenSendResponseFinish();

                        //发送响应包
                        if (responsePackage != null)
                        {
                            //为响应数据包添加RequestId
                            responsePackage.RequestId = requestPackage.RequestId;

                            //发送响应包
                            if (!XiepIoHelper.SendPackage(networkStream, responsePackage))
                            {
                                pushLog("错误:发送响应包失败:" + remoteInetAddress + "   |   " + responsePackage);
                            }
                            //触发发送响应后事件
                            AfterSendResponseArgs afterSendResponseArgs = new AfterSendResponseArgs(clientConnectionInfoArgs, requestPackage, responsePackage);
                            if (AfterSendResponse != null)
                            {
                                AfterSendResponse.Invoke(this, afterSendResponseArgs);
                            }

                            if (isDisconnectWhenSendResponseFinish)
                            {
                                return;
                            }
                        }
                    }
                }
            }
            catch { }
            finally
            {
                //触发与客户端连接断开事件
                if (ClientDisconnected != null)
                {
                    ClientDisconnected.Invoke(this, clientConnectionInfoArgs);
                }

                lock (_connectedClientList)
                {
                    _connectedClientList.Remove(socket);
                }
                try
                {
                    socket.Close();
                }
                catch (Exception ex)
                {
                    pushLog("关闭Socket时异常:" + ex.ToString());
                }
            }
        }
コード例 #11
0
ファイル: ServerControl.cs プロジェクト: jackizhang/Chat
 //update UI using the UI context
 private void TCPServer_ClientConnected(object sender, ClientConnectedArgs e)
 {
     _ui.Post(UpdateClientConnected, e);
 }
コード例 #12
0
ファイル: Service.cs プロジェクト: StarCheater/ServiceExample
 private void ServerOnClientConnected(object sender, ClientConnectedArgs e)
 {
     Console.WriteLine("Connected");
 }
コード例 #13
0
ファイル: Server.cs プロジェクト: alexndrejoly/csharpmlib
        void Poslusanje()
        {
            listener.Start();
            while (!stopped)
            {
                if ((paused) || (client_num >= maxClients))
                    Thread.Sleep(30);


                TcpClient client = listener.AcceptTcpClient();

                ClientConnectedArgs cca = new ClientConnectedArgs(client_num);
                ClientConnected(this, cca);

                client_num++;

                
                ConnectedClient cl = new ConnectedClient(client);
                clients.Add(cl);
                accepted = false;
                Thread thr = new Thread(Poslusaj);
                thr.IsBackground = true;
                thr.Start();


                while (!accepted)
                    Thread.Sleep(5);

            }
        }
コード例 #14
0
        void IObserver <ClientConnectedArgs> .OnNotified(object sender, ClientConnectedArgs eventArgs)
        {
            var message = string.Format("Controller connected to host at {0}", eventArgs.RemoteEndPoint);

            _view.UpdateStatus(message);
        }