public void setupConnection() { displayLine("Client started"); displayLine("Polling IP addresses"); try { clientSocket = new TcpClient(); displayLine("Checking IP address:" + CerebroClient.Properties.Settings.Default.ServerIP); clientSocket.Connect(CerebroClient.Properties.Settings.Default.ServerIP, 6669); displayLine("Server Connected"); getMyIP(); NetworkStream serverStream = clientSocket.GetStream(); byte[] outStream = Encoding.ASCII.GetBytes(myIP + "$$"); serverStream.Write(outStream, 0, outStream.Length); serverStream.Flush(); refreshConnectedClientList(); pollingThread = new PollingThread(this, myIP, clientSocket); polling = new Thread(new ThreadStart(pollingThread.poll)); polling.Start(); getName(); return; } catch (Exception) { displayLine("No server found in that IP"); } displayLine("Server Not Found"); }
private void disconnectToolStripMenuItem_Click(object sender, EventArgs e) { clientSocket.Close(); myIP = ""; name = ""; pollingThread = null; if (polling != null) { polling.Abort(); } polling = null; }