private void btnConnect_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         client.Connect("127.0.0.1", 1111);
         client.Write(">>> " + username + " just joined! <<<\n");
         btnConnect.IsEnabled        = false;
         connectedToTheServerAs.Text = "You are connected to the server as: " + username; //Connected to server as message
     }
     catch (Exception ex)                                                                 //if the server is anactive but the user still presses the connect button
     {
         System.Windows.MessageBox.Show("Server is not active");
         btnConnect.IsEnabled = true;
     }
 }
Exemple #2
0
 public void bconnect_Click(object sender, EventArgs e)
 {
     if (txtname.Text == "")
     {
         MessageBox.Show("Insert Name!");
     }
     else if (nsv != "y")
     {
         MessageBox.Show("Click Save Name!");
     }
     else if (nsv == "y")
     {
         try{
             Client.Connect(txthost.Text, Convert.ToInt32(txtport.Text));
             Client.Write("User:"******";" + " is connected to server");
             cn = "y";
             bconnect.Enabled = false;
         }
         catch
         {
             MessageBox.Show("Can't connect to server");
         }
     }
 }
Exemple #3
0
        public static Message WriteAndGetReply(this SimpleTcpClient client,
                                               string data,
                                               TimeSpan timeout)
        {
            Message mReply = null;

            void onReceived(object s,
                            Message e) => mReply = e;

            client.DataReceived += onReceived;
            client.Write(data);
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            while (mReply == null && stopwatch.Elapsed < timeout)
            {
                Thread.Sleep(10);
            }
            client.DataReceived -= onReceived;
            return(mReply);
        }
 private void btnConnect_Click(object sender, RoutedEventArgs e)
 {
     btnConnect.IsEnabled = false; //prevents us from clicking the button
     client.Connect(txtHost.Text, Convert.ToInt32(txtPort.Text));
     client.Write("                         " + username + " just joined!\n");
 }