public BasicTcpPacket getPacket(byte[] bytes) { BasicTcpPacket packet; switch (bytes[BasicTcpPacket.PKT_POS_TYPE]) { case BasicTcpPacket.PKT_TYPE_DISCONNECT: packet = new StandardDisconnectPacket(); break; case BasicTcpPacket.PKT_TYPE_DISCONNECT_ACK: packet = new StandardDisconnectAckPacket(); break; case BasicTcpPacket.PKT_TYPE_DISCONNECT_RS: packet = new StandardDisconnectRsPacket(); break; case BasicTcpPacket.PKT_TYPE_CONNECT_RS_ACK: packet = new StandardConnectRsAckPacket(); break; case BasicTcpPacket.PKT_TYPE_CONNECT_NAME_RS: packet = new StandardNamedConnectRsPacket(); break; case BasicTcpPacket.PKT_TYPE_CONNECT_NAME_RQ: packet = new StandardNamedConnectRqPacket(); break; case BasicTcpPacket.PKT_TYPE_DATA: packet = new StandardTcpDataPacket(); break; case BasicTcpPacket.PKT_TYPE_ACK: packet = new StandardAckPacket(); break; case BasicTcpPacket.PKT_TYPE_NOP: packet = new StandardTcpNopPacket(); break; default: throw new UnknownPacketException("Failed to determine packet type"); } packet.ProcessPacket(bytes); return packet; }
public void ProcessDisconnectRs(StandardDisconnectRsPacket packet) { Logger.Debug("Processing Disconnect Response " + packet); // In a connection response, ConnectionId is set to the same as the connection request ConnectionId if (_disconnectEvents.ContainsKey(packet.ConnectionId)) { AutoResetEvent disconnectEvent = _disconnectEvents[packet.ConnectionId]; _disconnectEvents.Remove(packet.ConnectionId); disconnectEvent.Set(); } else { // we know nothing about this (probably timed out), close this connection Logger.Warn("Got a disconnect Response with an Id we don't have [" + packet.ConnectionId + "], ignoring"); } }