public override void OnSerializeData(BitStream bitStream, ulong guid, int packet_size) { CustomIDs packet_id = (CustomIDs)bitStream.ReadByte();//the first byte of the packet is id, the rest is data switch (packet_id) { case CustomIDs.CLIENT_DATA: Debug.Log("[Server] Received client data from " + peer.GetAddress(guid, true) + " with guid " + guid); //creating a client data structure and putting it in a dictionary Clients.Add(guid, new ClientData(guid, bitStream.ReadString())); /* we inform the client that his data is accepted, we send it via a reliable channel */ using (PooledBitStream bsIn = BitStreamPool.GetBitStream()) { //be sure to reset the bitstream! If you do not do this the old recorded data will be sent bsIn.Reset(); //Write the packet id as a byte so that the client knows how to process the packet bsIn.Write((byte)CustomIDs.CLIENT_DATA_ACCEPTED); //As an example, we will send the text to the client in the load bsIn.Write("RakNet top... SosiPisos"); //we send data from bitstream to the client using its unique guid SendToClient(bitStream, guid, PacketPriority.IMMEDIATE_PRIORITY, PacketReliability.RELIABLE, 0); } break; } }
public override void OnSerializeData(BitStream bitStream, int packet_size) { CustomIDs packet_id = (CustomIDs)bitStream.ReadByte(); switch (packet_id) { case CustomIDs.CLIENT_DATA_ACCEPTED: Debug.LogWarning("[Client] Server accepted client data... Text = " + bitStream.ReadString()); break; } }