private void PodtrzymaniePołączenia() { try { while (true) { TcpClient tcpClient = new TcpClient(Around_Lib.GetIpByConnectionKey(ConnectionKeyBox.Text), 5759); NetworkStream stream = tcpClient.GetStream(); byte[] bytes = Encoding.UTF8.GetBytes(AdresIP); stream.Write(bytes, 0, bytes.Length); tcpClient.Close(); connected = true; Thread.Sleep(2000); } } catch { this.Invoke((MethodInvoker) delegate { ConnectToServerBtn.BackColor = Color.FromArgb(26, 35, 126); ConnectToServerBtn.Enabled = true; ConnectToServerBtn.Text = "Połącz"; ConnectionKeyBox.Enabled = true; ConnectionKeyBox.Visible = true; ConnectToServerBtn.Visible = true; ConnectionKeyLabel.Text = "Kod połączenia: " + ConnectionKeyBox.Text; MessageBox.Show("Utracono połączenie z serwerem!", "Utracono połączenie"); }); } }
private void PierwszePołączenie() { try { TcpClient tcpClient = new TcpClient(Around_Lib.GetIpByConnectionKey(ConnectionKeyBox.Text), 5759); NetworkStream stream = tcpClient.GetStream(); byte[] bytes = Encoding.UTF8.GetBytes(AdresIP); stream.Write(bytes, 0, bytes.Length); tcpClient.Close(); connected = true; } catch { } }