public override bool StartPing(string ip) { lock (SocketUdpNativeDynamic.syncer) { base.Init(); if (pConnectionHandler == IntPtr.Zero) { pConnectionHandler = SocketUdpNativeDynamic.egconnect(ip); SocketUdpNativeDynamic.egservice(pConnectionHandler); byte state = SocketUdpNativeDynamic.eggetState(pConnectionHandler); while (state == (byte)NativeSocketState.Connecting) { SocketUdpNativeDynamic.egservice(pConnectionHandler); state = SocketUdpNativeDynamic.eggetState(pConnectionHandler); } } PingBytes[PingBytes.Length - 1] = PingId; SocketUdpNativeDynamic.egsend(pConnectionHandler, PingBytes, PingBytes.Length); SocketUdpNativeDynamic.egservice(pConnectionHandler); PingBytes[PingBytes.Length - 1] = (byte)(PingId - 1); return(true); } }
public override bool Done() { lock (SocketUdpNativeDynamic.syncer) { if (this.GotResult || pConnectionHandler == IntPtr.Zero) { return(true); } int available = SocketUdpNativeDynamic.egservice(pConnectionHandler); if (available < PingLength) { return(false); } int pingBytesLength = PingBytes.Length; int bytesInRemainginDatagrams = SocketUdpNativeDynamic.egread(pConnectionHandler, PingBytes, ref pingBytesLength); this.Successful = (PingBytes != null && PingBytes[PingBytes.Length - 1] == PingId); //Debug.Log("Successful: " + this.Successful + " bytesInRemainginDatagrams: " + bytesInRemainginDatagrams + " PingId: " + PingId); this.GotResult = true; return(true); } }