C# 在IPv6(NAT64)环境中,networkStream.beginhead执行';行不通

C# 在IPv6(NAT64)环境中,networkStream.beginhead执行';行不通,c#,unity3d,tcpclient,netstream,C#,Unity3d,Tcpclient,Netstream,下面的代码在IPV4中运行良好,在IPv6(NAT64)环境中,它可以连接服务器并成功发送消息,它可以从服务器捕获数据,但是永远不会执行回调OnRead 这困扰了我很长时间 private TcpClient client = null; private const int MAX_READ = 8192; private NetworkStream outStream = null; private byte[] byteBuffer = new byte[MAX_READ]; publi

下面的代码在IPV4中运行良好,在IPv6(NAT64)环境中,它可以连接服务器并成功发送消息,它可以从服务器捕获数据,但是永远不会执行回调OnRead

这困扰了我很长时间

private TcpClient client = null;
private const int MAX_READ = 8192;
private NetworkStream outStream = null;
private byte[] byteBuffer = new byte[MAX_READ];


public void ConnectServerByIP(string ip, int port) {

    client = new TcpClient(AddressFamily.InterNetworkV6);


    client.SendTimeout = 1000;
    client.ReceiveTimeout = 1000;
    client.NoDelay = true;

    IPAddress ipAddr = IPAddress.Parse(ip);

    try {
        client.BeginConnect(ipAddr, port, new AsyncCallback(OnConnect), null);
    } catch (Exception e) {
        Close(); Debug.LogError(e.Message);
    }

}

void OnConnect(IAsyncResult asr) {
    outStream = client.GetStream();

    client.GetStream ().BeginRead (byteBuffer, 0, MAX_READ,new  AsyncCallback(OnRead), null);

    NetworkManager.AddEvent(Protocal.Connect, new ByteBuffer());
}

void OnRead(IAsyncResult asr) {
    Debug.Log ("Hello~");
}

如果您
EndConnect
,则可能会有所帮助,以便您可以拾取任何异常,等等:“异步BeginConnect操作必须通过调用EndConnect方法来完成。通常,该方法由asyncCallback委托调用。”如果您
EndConnect
,则可能会有所帮助,以便您可以拾取任何异常,等等:“异步BeginConnect操作必须通过调用EndConnect方法来完成。通常,该方法由asyncCallback委托调用。”