In the IPv6(NAT64) environment,networkStream.BeginRead does't work

89 views Asked by At

The following code works well in IPV4,And,In the IPv6(NAT64) environment,it can connect the server and send message success,It can capture the data from server, But,the callback OnRead never be executed.

It's been bothering me for a long time.

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~");
}
0

There are 0 answers