예제 #1
0
 private void bConnect_Click(object sender, RoutedEventArgs e)
 {
     if (String.IsNullOrEmpty(ClientName.Text.Trim()) || String.IsNullOrEmpty(ClientConnectIp.Text.Trim()) || String.IsNullOrEmpty(ClientConnectPort.Text.Trim()))
     {
         MessageBox.Show("Какое-то из полей пустое!");
     }
     else
     {
         try
         {
             Socket     socket = new Socket(SocketType.Stream, ProtocolType.Tcp);
             IPEndPoint ip     = new IPEndPoint(IPAddress.Parse(ClientConnectIp.Text.Trim()), Convert.ToInt32(ClientConnectPort.Text.Trim()));
             socket.Connect(ip);
             string name = ClientName.Text.Trim();
             SocketFunctions.SendString(socket, name);
             MainWindow window = new MainWindow(socket);
             window.Show();
             this.Close();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
예제 #2
0
 private void bSendMessage_Click(object sender, RoutedEventArgs e)
 {
     if (!String.IsNullOrEmpty(ClientMessage.Text.Trim()))
     {
         SocketFunctions.SendInt(socket, 0);
         SocketFunctions.SendString(socket, ClientMessage.Text.Trim());
         ClientMessage.Text = "";
     }
 }
예제 #3
0
        async Task GetMessageAsync()
        {
            while (true)
            {
                await Task.Delay(500);

                string x = await Task.Run(() =>
                {
                    while (true)
                    {
                        if (SocketFunctions.RecieveInt(socket) == 0)
                        {
                            break;
                        }
                    }
                    return(SocketFunctions.RecieveString(socket));
                });

                string[] msg = x.Split(new[] { "%&%" }, StringSplitOptions.None);
                AllMessages.AppendText(msg[0] + " : " + msg[1] + " " + Environment.NewLine);
            }
        }
예제 #4
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     SocketFunctions.SendInt(socket, 1);
 }