private void ConnectButton_Click(object sender, RoutedEventArgs e) { MainWindow mw = null; try { string hostname = HostnameBox.Text; IPAddress ip; TcpClient tcp = null; int port = Int32.Parse(PortConnect.Text); if(IPAddress.TryParse(hostname,out ip)) { IPEndPoint iep = new IPEndPoint(ip,port); tcp = new TcpClient(); tcp.Connect(iep); } else { tcp = new TcpClient(hostname, port); } tcp.Close(); mw = new MainWindow(hostname, port); mw.Show(); this.Close(); } catch (Exception) { } }
private void Button_Click(object sender, RoutedEventArgs e) { MainWindow mw = null; try { int port = Int32.Parse(PortServer.Text); System.Diagnostics.Process.Start("Broadcaster.exe", PortServer.Text); Thread t = Thread.CurrentThread; System.Timers.Timer ti = new System.Timers.Timer(); ti.Interval = 1000; ti.Start(); while (!ti.Enabled) ; ti.Stop(); mw = new MainWindow("localhost", port); mw.Show(); this.Close(); } catch (Exception) { } }