Example #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();
        }
Example #2
0
        /// <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();
        }
Example #3
0
 public void Remove(MayKhach client)
 {
     client.Dispose();
     dsMayKhach.Remove(client);
 }
Example #4
0
 public void Add(MayKhach client)
 {
     dsMayKhach.Add(client);
 }
 public SeverMessageProcessor(MayKhach client, ClientManager clientManage)
 {
     this.clientManager  = clientManage;
     this.client         = client;
     ListReiceveMassager = new List <MessageBase>();
 }
Example #6
0
 private void SendToClient(MayKhach client, MessageBase message)
 {
     client.Send(TryConvertObject.SwithToBinnary(message));
 }
Example #7
0
 private void SendToClient(MayKhach client, MessageBase message)
 {
     Logging.Debug("Send to:" + message.ToString());
     client.Send(ObjectConvert.Object2Binary(message));
 }
 public ServerMessageProcessor(ClientManager manager, MayKhach client)
 {
     this.clientManager = manager;
     this.client        = client;
     Response           = new List <MessageBase>();
 }