[英]Canot create udp connection on mono
我無法創建UDP連接:
public void Connect(String host, int port)
{
System.Net.IPAddress address = Dns.GetHostAddresses (host)[0];
this.hostport = new IPEndPoint(address, port);
this.socket = new Socket(
AddressFamily.InterNetwork,
SocketType.Dgram,
ProtocolType.Udp
);
this.socket.BeginConnect(this.hostport, new AsyncCallback(socket__onConnect), this.socket);
}
private void socket__onConnect(IAsyncResult ar)
{
// It is never called on udp connections :(
try
{
Socket client = (Socket) ar.AsyncState;
client.EndConnect(ar);
Console.WriteLine("Success!");
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
嘗試連接,但永遠不會調用socket__onConnect。
使用TCP可以正常工作,但是UDP doeas不能工作。
我有權限連接udp端口:
nc -v -u host.com 53
工作正常。
單聲道錯誤? 嘗試這個:
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp) { ExclusiveAddressUse = true ; } ;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.