private void WritePacket(StreamingPacketType StreamingPacketType, EStreamChannel EStreamChannel, byte[] Data) { List <byte> Output = new List <byte>(); Output.Add((byte)StreamingPacketType); Output.Add(0); //Repeat count Output.Add(SenderID); Output.Add(RecieverID); Output.Add((byte)EStreamChannel); Output.AddRange(BitConverter.GetBytes((Int16)0)); //Unknown Output.AddRange(BitConverter.GetBytes(PacketSquenceIDs[(int)StreamingPacketType])); Output.AddRange(BitConverter.GetBytes(Environment.TickCount)); UdpClient.Send(Output.ToArray(), Output.Count); }
private void ReadPacket(byte[] MessageData) { try { StreamingPacketType PacketType = (StreamingPacketType)MessageData[0]; switch (PacketType) { case StreamingPacketType.Connect: RecieverID = (byte)(MessageData[2] & 0xff); CAuthenticationRequestMsg CAuthenticationRequestMsg = new CAuthenticationRequestMsg(); CAuthenticationRequestMsg.version = EStreamVersion.k_EStreamVersionCurrent; CAuthenticationRequestMsg.token = AuthToken; ProcessOutgoingMessage <CAuthenticationRequestMsg>(StreamingPacketType.Control, CAuthenticationRequestMsg); break; case StreamingPacketType.ConnectResponse: break; case StreamingPacketType.Control: break; case StreamingPacketType.ControlAcknoledge: break; case StreamingPacketType.ControlContinued: break; case StreamingPacketType.Data: break; case StreamingPacketType.Disconnect: break; } } catch (Exception e) { ExceptionHandler(e); } }
private void ProcessOutgoingMessage <T>(StreamingPacketType PacketType, object Message) { List <byte> OutgoingData = new List <byte>(); using (var stream = new MemoryStream()) { Serializer.Serialize <T>(stream, (T)Message); byte[] MessageData = stream.GetBuffer().Take((Int32)stream.Length).ToArray(); switch (PacketType) { case StreamingPacketType.Control: OutgoingData.Add((byte)EStreamControlMessageDictionary[typeof(T)]); OutgoingData.AddRange(MessageData); WritePacket(StreamingPacketType.Control, EStreamChannel.k_EStreamChannelControl, OutgoingData.ToArray()); break; case StreamingPacketType.ControlAcknoledge: break; default: throw new Exception("Unsupported message type"); } } }