/// <summary> /// Raises the send thread event. /// </summary> /// <param name="o">O.</param> public void OnSendThread() { try{ if (!socket.Poll(10000000, SelectMode.SelectWrite)) { socket.Close(); } else { while (true) { if (!Connected()) { break; } if (sendQueue.Count > 0) { INetPacket packet = default(INetPacket); lock (sendQueue) { packet = sendQueue.Dequeue(); } if (packet != null) { int nSendBytes = socket.Send(packet.GetBytes(), 0, packet.Size + sizeof(int), SocketFlags.None); #if UNITY_EDITOR UnityEngine.Debug.Log(string.Format("Send packet type({0}) size({1})", packet.Type, nSendBytes)); #endif } } Thread.Sleep(10); } } } catch (Exception e) { #if UNITY_EDITOR UnityEngine.Debug.LogError(e.Message); #endif PostPacket( new INetPacket(PacketType.SOCKET_DISCONNECT) ); } sendThread.Abort(); }
/// <summary> /// Determines whether the specified <see cref="INetPacket"/> is equal to the current <see cref="INetPacket"/>. /// </summary> /// <param name="other">The <see cref="INetPacket"/> to compare with the current <see cref="INetPacket"/>.</param> /// <returns><c>true</c> if the specified <see cref="INetPacket"/> is equal to the current <see cref="INetPacket"/>; otherwise, <c>false</c>.</returns> public bool Equals(INetPacket other) { if (size == other.Size) { byte[] otherData = other.GetBytes(); for (int i = 0; i < size; i++) { if (data[i] != otherData[i]) { return(false); } } return(true); } return(false); }