private void connect() { m_connecting=true; while(true) { if(!m_connected) { try { // Establish the remote endpoint for the socket. // The name of the // remote device is "host.contoso.com". // Create a TCP/IP socket. sender = new myTcpClient(); // Connect the socket to the remote endpoint. Catch any errors. try { /* IPAddress ipAddress = Dns.Resolve(host).AddressList[0]; IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, 11000); */ sender.Connect(m_host,m_port);; writer = new StreamWriter(sender.GetStream(), Encoding.ASCII); reader = new StreamReader(sender.GetStream(), Encoding.ASCII); m_connected=true; m_connecting=false; // break; Console.WriteLine("Socket connected to {0}", sender.ToString()); } catch (ArgumentNullException ane) { Console.WriteLine("ArgumentNullException : {0}",ane.ToString()); m_connected=false; } catch (SocketException se) { Console.WriteLine("SocketException : {0}",se.ToString()); m_connected=false; } } catch (Exception e) { Console.WriteLine("Unexpected exception : {0}", e.ToString()); m_connected=false; } } Thread.Sleep(200); } }
private void connect() { m_connecting = true; while (true) { if (!m_connected) { try { // Establish the remote endpoint for the socket. // The name of the // remote device is "host.contoso.com". // Create a TCP/IP socket. sender = new myTcpClient(); // Connect the socket to the remote endpoint. Catch any errors. try { /* * IPAddress ipAddress = Dns.Resolve(host).AddressList[0]; * IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, 11000); */ sender.Connect(m_host, m_port);; writer = new StreamWriter(sender.GetStream(), Encoding.ASCII); reader = new StreamReader(sender.GetStream(), Encoding.ASCII); m_connected = true; m_connecting = false; // break; Console.WriteLine("Socket connected to {0}", sender.ToString()); } catch (ArgumentNullException ane) { Console.WriteLine("ArgumentNullException : {0}", ane.ToString()); m_connected = false; } catch (SocketException se) { Console.WriteLine("SocketException : {0}", se.ToString()); m_connected = false; } } catch (Exception e) { Console.WriteLine("Unexpected exception : {0}", e.ToString()); m_connected = false; } } Thread.Sleep(200); } }