void OnCommandReceived(UdpBitStream buffer) { if (ParseHeader(ref buffer)) { stats.CommandsReceived += 1; buffer.Ptr = UdpHeader.GetSize(socket); UdpCommandType cmd = (UdpCommandType)buffer.ReadByte(8); switch (cmd) { case UdpCommandType.Connect: OnCommandConnect(buffer); break; case UdpCommandType.Accepted: OnCommandAccepted(buffer); break; case UdpCommandType.Refused: OnCommandRefused(buffer); break; case UdpCommandType.Disconnected: OnCommandDisconnected(buffer); break; case UdpCommandType.Ping: OnCommandPing(buffer); break; default: ConnectionError(UdpConnectionError.IncorrectCommand); break; } } }
internal void SendCommand(UdpCommandType cmd) { if (CheckCanSend(true) == UdpSendFailReason.None) { UdpStream stream = socket.GetWriteStream(mtu << 3, UdpSocket.HeaderBitSize); stream.WriteByte((byte)cmd, 8); UdpHeader header = MakeHeader(false); header.Pack(stream, socket); UdpHandle handle = MakeHandle(ref header); handle.Object = null; if (SendStream(stream, handle, false)) { // track stats stats.PacketSent((uint)stream.Ptr >> 3); socket.Statistics.PacketSent((uint)stream.Ptr >> 3); } else { // should we do something here????? } } }
internal void SendCommand(UdpCommandType cmd) { if (CheckCanSend(true) == UdpSendFailReason.None) { UdpBitStream stream = new UdpBitStream(socket.GetWriteBuffer(), mtu, UdpHeader.GetSize(socket)); stream.WriteByte((byte)cmd, 8); UdpHeader header = MakeHeader(false); header.Pack(new UdpBitStream(stream.Data, mtu, 0), socket); UdpHandle handle = MakeHandle(ref header); handle.Object = null; if (SendStream(stream, handle, false) == false) { // do something here? } stats.CommandSent += 1; } }
internal void SendCommand(UdpCommandType cmd) { if (CheckCanSend(true) == UdpSendFailReason.None) { UdpBitStream stream = new UdpBitStream(socket.GetWriteBuffer(), mtu, UdpHeader.GetSize(socket)); stream.WriteByte((byte) cmd, 8); UdpHeader header = MakeHeader(false); header.Pack(new UdpBitStream(stream.Data, mtu, 0), socket); UdpHandle handle = MakeHandle(ref header); handle.Object = null; if (SendStream(stream, handle, false) == false) { // do something here? } stats.CommandSent += 1; } }
internal void SendCommand(UdpCommandType cmd) { if (CheckCanSend(true) == UdpSendFailReason.None) { UdpStream stream = socket.GetWriteStream(mtu << 3, UdpSocket.HeaderBitSize); stream.WriteByte((byte) cmd, 8); UdpHeader header = MakeHeader(false); header.Pack(stream, socket); UdpHandle handle = MakeHandle(ref header); handle.Object = null; if (SendStream(stream, handle, false)) { // track stats stats.PacketSent((uint) stream.Ptr >> 3); socket.Statistics.PacketSent((uint) stream.Ptr >> 3); } else { // should we do something here????? } } }
internal void SendCommand(UdpCommandType cmd) { SendCommand(cmd, null); }