コード例 #1
0
ファイル: ServerPart.cs プロジェクト: 0000duck/bird
        private void accept()
        {
            serverThread = new Thread(
                () =>
            {
                while (true)
                {
                    if (connectionFinder != null)
                    {
                        try
                        {
                            Socket acceptedSocket = connectionFinder.Accept();

                            IPAddress address = (acceptedSocket.RemoteEndPoint as IPEndPoint).Address;

                            string id = IDMaker.getID(address);

                            OnSocketCreated(id, acceptedSocket);     //socket created for new client evetn fire
                        }

                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            serverThread.Abort();
                        }
                    }
                }
            });

            serverThread.Start();
        }
コード例 #2
0
        protected virtual void OnsocketConnected(IPEndPoint endPoint)
        {
            if (SocketConnected != null)
            {
                string idOfServer = IDMaker.getID(endPoint.Address);

                SocketConnected(this, new SocketAddedEventArgs()
                {
                    id = idOfServer, socket = connectingSocket
                });
            }
        }