Esempio n. 1
0
 public Client(String serverHost)
 {
     try
     {
         this.serverHost = serverHost;
         Console.WriteLine("Подключение к {0}", this.serverHost);
         cSocket = new Socket(SocketType.Stream, ProtocolType.Tcp);
         cSocket.Connect(this.serverHost, port);
         net = new NetMessaging(cSocket);
         net.LoginCmdReceived    += OnLogin;
         net.UserListCmdReceived += OnUserList;
         net.StartCmdReceived    += OnStart;
         net.MessageCmdReceived  += OnMessage;
         new Thread(() =>
         {
             try
             {
                 net.Communicate();
             }
             catch (Exception ex)
             {
                 Console.WriteLine("Не удалось получить данные. Завершение соединения...");
             }
         }).Start();
     }
     catch (Exception e)
     {
         Console.WriteLine("Что-то пошло не так... :(");
     }
 }
Esempio n. 2
0
 public Client(String serverHost)
 {
     try
     {
         this.serverHost = serverHost;
         Console.WriteLine("Подключение к {0}", this.serverHost);
         cSocket = new Socket(SocketType.Stream, ProtocolType.Tcp);
         cSocket.Connect(this.serverHost, port);
         net = new NetMessaging(cSocket);
         net.DataReceived += OnResult;
         //подписки
         new Thread(() =>
         {
             try
             {
                 net.Communicate();
             }
             catch (Exception ex)
             {
                 //exception
             }
         }).Start();
     }
     catch (Exception e)
     {
         //exception
     }
 }
Esempio n. 3
0
        public void Start()
        {
            isConnected = false;
            try {
                ClientLog.Invoke(String.Format("[Server]: Подключение к {0}", this.serverHost));
                cSocket = new Socket(SocketType.Stream, ProtocolType.Tcp);
                cSocket.Connect(this.serverHost, port);
                net = new NetMessaging(cSocket);

                net.LoginCmdReceived    += OnLogin;
                net.UserListCmdReceived += OnUserList;
                net.StartCmdReceived    += OnStart;
                net.MessageCmdReceived  += OnMessage;

                communicate = new Thread(() => {
                    try {
                        net.Communicate();
                    } catch (Exception) {
                        ClientLog.Invoke("[Server]: Не удалось получить данные. Завершение соединения...");
                    }
                });
                communicate.Start();
            } catch (Exception) {
                ClientLog.Invoke("[Server]: Что-то пошло не так... :(");
            }
        }
Esempio n. 4
0
File: Form1.cs Progetto: MilyaZ/Chat
 void Communicate()
 {
     try
     {
         net.Communicate();
     }
     catch (Exception ex)
     {
         OnComment("Не удалось получить данные. Завершение соединения...");
         //OnNameError(0);
     }
 }
Esempio n. 5
0
 //public string Name { get; private set; }
 public ConnectedClient(Socket s)
 {
     cSocket           = s;
     net               = new NetMessaging(cSocket);
     net.DataReceived += OnData;
     new Thread(() =>
     {
         try
         {
             net.Communicate();
         }
         catch (Exception ex)
         {
             Console.WriteLine("Не удалось получить данные от клиента :(");
             clients.Remove(this);
         }
     }).Start();
 }
Esempio n. 6
0
 public ConnectedClient(Socket s)
 {
     cSocket = s;
     net     = new NetMessaging(cSocket);
     //net.SendData("LOGIN", "?");
     //net.LoginCmdReceived += OnLogin;
     net.MessageCmdReceived += OnMessage;
     net.AppendCmdReceived  += Append;
     new Thread(() =>
     {
         try
         {
             net.Communicate();
         }
         catch (Exception)
         {
             Console.WriteLine("Не удалось получить данные от клиента :(");
             clients.Remove(this);
         }
     }).Start();
 }
Esempio n. 7
0
 private void Connecting()
 {
     try
     {
         //Console.WriteLine("Подключение к {0}", this.sHost);
         txtChat.AppendText("Подключение к " + usHost.ToString() + Environment.NewLine);
         cSocket = new Socket(SocketType.Stream, ProtocolType.Tcp);
         cSocket.Connect(usHost, port);
         net = new NetMessaging(cSocket);
         net.LoginCmdReceived += OnLogin;
         //net.SendData("LOGIN", txtUserName.Text);
         net.UserListCmdReceived  += OnUserList;
         net.StartCmdReceived     += OnStart;
         net.MessageCmdReceived   += OnMessage;
         net.CheckNameCmdReceived += OnCheckName;
         new Thread(() =>
         {
             try
             {
                 net.Communicate();
             }
             catch (Exception ex)
             {
                 Console.WriteLine("Не удалось получить данные. Завершение соединения...");
                 //txtChat.AppendText("Не удалось получить данные. Завершение соединения...");
             }
         }).Start();
     }
     catch (Exception e)
     {
         //Console.WriteLine("Что-то пошло не так... :(");
         txtChat.AppendText("Что-то пошло не так... :(");
         Stop();
         btnConnect.Text     = "Подключить";
         txtUserName.Enabled = true;
         txtHost.Enabled     = true;
         btnSend.Enabled     = false;
     }
 }
Esempio n. 8
0
 public ConnectedCLient(Socket s, Server serv)
 {
     this.serv = serv;
     cSocket   = s;
     net       = new NetMessaging(cSocket);
     //net.SendData("LOGIN", "?");
     net.LoginCmdReceived    += OnLogin;
     net.MessageCmdReceived  += OnMessage;
     net.UserListCmdReceived += OnUsers;
     net.PrivateReceived     += OnPrivate;
     net.SendInfo            += OnLog;
     new Thread(() =>
     {
         try
         {
             net.Communicate();
         }
         catch (Exception ex)
         {
             Console.WriteLine("Не удалось получить данные от клиента :(");
             clients.Remove(this);
         }
     }).Start();
 }