1

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~");
}
Wuzee
  • 11
  • 2
  • 2
    It would probably help if you `EndConnect` so that you can pick up any exceptions, etc. – Damien_The_Unbeliever Sep 12 '17 at 11:46
  • [MSDN](https://msdn.microsoft.com/en-us/library/ms145193(v=vs.110).aspx): "The asynchronous **BeginConnect operation must be completed** by calling the EndConnect method. Typically, the method is invoked by the asyncCallback delegate." – Fildor Sep 12 '17 at 12:04

0 Answers0