//Deserialze packet and return our packet struct. public async Task <PosPacket> Recieve() { var result = await Client.ReceiveAsync(); PosPacket temp = SerializationHandler.Deserialize <PosPacket>(result.Buffer); temp.Sender = result.RemoteEndPoint; return(temp); }
//Reply by serializing the packet info and sending to everyone excpet the sender of the packet public void Reply(PosPacket packet, Dictionary <IPEndPoint, Guid> clients) { //Dont send back position values to the client who sent us the values foreach (KeyValuePair <IPEndPoint, Guid> client in clients) { if (client.Value != packet.userID) { var datagram = SerializationHandler.Serialize <PosPacket>(packet); Client.Send(datagram, datagram.Length, client.Key); } } }
public void Update() { //Send our info to the server! PosPacket pac = new PosPacket() { Sender = new IPEndPoint(1, 1), userID = userGUID, Position = new SerializableVector3(this.transform.position), Rotation = new SerializableVector3(this.transform.rotation.eulerAngles) }; client.Send(pac); //Call the update players method. UpdatePlayers(); }
//Serialze and send off our packet public void Send(PosPacket packet) { var datagram = SerializationHandler.Serialize <PosPacket>(packet); Client.Send(datagram, datagram.Length); }