繁体   English   中英

Canot在单声道上创建udp连接

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM