private void clientSender()
 {
     int count = 0;
     while (!_cancellationToken)
     {
         //this is just for testing, in the future, use buffers, same as server
         Payload[] test = new Payload[1];
         test[0] = new Handshake();
         byte[] write_bytes = new Packet(1, test).Serialize();
         try
         {
             _serverSocket.SendTo(write_bytes, _serverEndpoint);
             count++;
         }
         catch (Exception e)
         {
             //Perhaps resend the message
         }
         Thread.Sleep(1000);
     }
     Debug.WriteLine("Client Sender terminated. Sent {0} messages", count);
 }
        private List<Payload> processPayloads(IPEndPoint source, Packet packet)
        {
            List<Payload> reply = new List<Payload>();
            bool knownClient = _clients.ContainsKey(source);
            bool ack = false;
            foreach (Payload p in packet.Payload)
            {
                Type type = p.GetType();
                if (!knownClient)
                {
                    if (type.Equals(typeof(Handshake)))
                    {
                        try
                        {
                            //Add rules for accepting new connections
                            _clients.Add(source, new ClientConnection());
                            knownClient = true;
                            ack = true;
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine("Exception while accepting handshake, " + e.Message);
                        }
                    }
                }
                else
                {
                    if (type.Equals(typeof(Player)))
                    {

                    }
                }
            }
            if (ack) {
                reply.Add(new Ack(packet.Seq));
            }
            return reply;
        }