Exemple #1
0
        // CreateClient: Creates a new TcpClient and attempts to connect to a Server asyncronously via the GameAddress and Port
        public static async Task CreateClient()
        {
            if (GameAddress == null || GamePort == 0)
            {
                throw new ArgumentNullException("Invalid GameAddress or GamePort");
            }
            else if (GameAddress.ToLower() == "localhost")
            {
                GameAddress = "127.0.0.1";
            }

            if (PlayerClient == null)
            {
                PlayerClient = new TcpClient
                {
                    NoDelay = true
                };
                await Task.Run(async() =>
                {
                    try
                    {
                        await PlayerClient.ConnectAsync(IPAddress.Parse(GameAddress), GamePort);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                });
            }
        }
Exemple #2
0
 // CreateServer: Creates a new TcpListener using the GameAddress and Port
 public static void CreateServer()
 {
     if (GameAddress == null || GamePort == 0)
     {
         throw new ArgumentNullException("Invalid GameAddress or GamePort");
     }
     else if (GameAddress.ToLower() == "localhost")
     {
         GameAddress = "127.0.0.1";
     }
     SocketServer = new TcpListener(IPAddress.Parse(GameAddress), GamePort);
     SocketServer.Start();
 }