-1
我有這樣的代碼:的foreach在DNS主機地址
IPHostEntry host = null;
Socket sock;
host = Dns.GetHostEntry("ip..");
foreach (IPAddress address in host.AddressList)
{
IPEndPoint ipe = new IPEndPoint(address, 7777);
sock = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
sock.Connect(ipe);
if (sock.Connected)
{
sock.SendTo(Encoding.UTF8.GetBytes("Hello world"), ipe);
}
}
此代碼確定本地主機上,但是當我寫VPS IP,代碼不工作,有什麼問題嗎?
什麼不起作用?該foreach,連接,還是別的?你是否收到任何錯誤信息或異常? – GTHvidsten
foreach不起作用,不,我沒有得到任何消息:( –
什麼是確切的'Dns.GetHostEntry()'線,當它不工作? – GTHvidsten