コード例 #1
0
        private void OnClientCloseConn(object sender, EventArgs e)
        {
            ClientPC clientPC = (ClientPC)sender;

            clientPCs.Remove(clientPC);

            clientPC.CloseSocket();
            clientPC = null;
        }
コード例 #2
0
        private void SocketListener_OnNewClientConnected(Object sender, SocketListenerEventArgs e)
        {
            foreach (ClientPC pc in clientPCs)
            {
                if (pc.Socket.RemoteEndPoint.AddressFamily.ToString() == e.socket.RemoteEndPoint.AddressFamily.ToString())
                {
                    //Do nothing if this PC is existing.
                    return;
                }
            }

            //Add new client
            ClientPC clientPC = new ClientPC(e.socket);

            clientPC.CloseMessageReceived += new EventHandler(OnClientCloseConn);
            clientPCs.Add(clientPC);

            CustomMessage msg = new CustomMessage(MessageType.CommonMessage, CommonMessage.CONN_ACCEPT);

            clientPC.SendCommonMessage(msg);
        }