Advertisement
Guest User

Untitled

a guest
Nov 7th, 2012
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. IPHostEntry ipHostInfo = System.Net.Dns.GetHostEntry("localhost");
  2. IPAddress ipAddress = ipHostInfo.AddressList[0];
  3. IPEndPoint remoteEP = new IPEndPoint(ipAddress, Port);
  4.  
  5. Sock = new Socket(remoteEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
  6. Sock.BeginConnect(remoteEP, new AsyncCallback(ConnectCallback), Sock);
  7.  
  8. System.Net.Sockets.SocketException (0x80004005): No connection could be made because the target machine actively refused it [::1]:7777
  9. at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
  10. at NotifierClient.AsynchronousClient.ConnectCallback(IAsyncResult ar) in *** :line 156
  11.  
  12. client.EndConnect(ar);
  13.  
  14. IPHostEntry ipHostInfo = System.Net.Dns.GetHostEntry("localhost");
  15.  
  16. IPAddress ipAddress = null;
  17. foreach(var addr in ipHostInfo.AddressList)
  18. {
  19. if(addr.AddressFamily == AddressFamily.InterNetwork) // this is IPv4
  20. {
  21. ipAddress = addr;
  22. break;
  23. }
  24. }
  25.  
  26. // at this point, ipAddress is either going to be set to the first IPv4 address
  27. // or it is going to be null if no IPv4 address was found in the list
  28. if(ipAddress == null)
  29. throw new Exception("Error finding an IPv4 address for localhost");
  30.  
  31. IPEndPoint remoteEP = new IPEndPoint(ipAddress, Port);
  32.  
  33. Sock = new Socket(remoteEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
  34. Sock.BeginConnect(remoteEP, new AsyncCallback(ConnectCallback), Sock);
  35.  
  36. IPHostEntry ipHostInfo = Dns.GetHostEntry("localhost");
  37. IPAddress ipAddress = ipHostInfo.AddressList[1];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement