コード例 #1
0
        internal void Connect()
        {
            var IP    = new IPEndPoint(IPAddress.Any, Port);
            var sever = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);

            sever.Bind(IP);
            Console.WriteLine("sever connected");
            Thread listen = new Thread(() =>
            {
                try
                {
                    while (true)
                    {
                        sever.Listen(1000);
                        var mayKhach = new MayKhach(sever.Accept());
                        Console.WriteLine("client connected ");
                        Thread receive       = new Thread(NhanTinNhan);
                        receive.IsBackground = true;
                        receive.Start(mayKhach);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("lỗi máy chủ " + ex);
                    Console.WriteLine("khắc phục lỗi==>> tạo lại máy chủ");
                    IP    = new IPEndPoint(IPAddress.Any, Port);
                    sever = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
                }
            });

            listen.IsBackground = true;
            listen.Start();
        }
コード例 #2
0
ファイル: Sever.cs プロジェクト: nguyenquanglinh/BaiTap
        /// <summary>
        /// Start server và bắt đầu lắng nghe từ client
        /// </summary>
        void Connect()
        {
            var    ip    = new IPEndPoint(IPAddress.Any, Port);
            Socket Sever = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);

            Sever.Bind(ip);
            Logging.Info("Server started");
            Thread listen = new Thread(() =>
            {
                try
                {
                    while (true)
                    {
                        Sever.Listen(100);
                        var client   = Sever.Accept();
                        var mayKhach = new MayKhach(client);
                        Logging.Info("Client connected");
                        Thread receive       = new Thread(NhanTinVe);
                        receive.IsBackground = true;
                        receive.Start(mayKhach);
                    }
                }
                catch
                {
                    ip    = new IPEndPoint(IPAddress.Any, Port);
                    Sever = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
                }
            });

            listen.IsBackground = true;
            listen.Start();
        }
コード例 #3
0
 public void Remove(MayKhach client)
 {
     client.Dispose();
     dsMayKhach.Remove(client);
 }
コード例 #4
0
 public void Add(MayKhach client)
 {
     dsMayKhach.Add(client);
 }
コード例 #5
0
 public SeverMessageProcessor(MayKhach client, ClientManager clientManage)
 {
     this.clientManager  = clientManage;
     this.client         = client;
     ListReiceveMassager = new List <MessageBase>();
 }
コード例 #6
0
 private void SendToClient(MayKhach client, MessageBase message)
 {
     client.Send(TryConvertObject.SwithToBinnary(message));
 }
コード例 #7
0
ファイル: Sever.cs プロジェクト: nguyenquanglinh/BaiTap
 private void SendToClient(MayKhach client, MessageBase message)
 {
     Logging.Debug("Send to:" + message.ToString());
     client.Send(ObjectConvert.Object2Binary(message));
 }
コード例 #8
0
 public ServerMessageProcessor(ClientManager manager, MayKhach client)
 {
     this.clientManager = manager;
     this.client        = client;
     Response           = new List <MessageBase>();
 }