// 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; } }); } }
/// <summary> /// 返回更新服务器地址,如果有多个,随机一个,无为空 /// </summary> /// <returns>更新服务器地址</returns> public static GameAddress GetUpdaterAddress() { GameAddress address = new GameAddress(); address.strIPAddress = mResourceServerIp + "/" + Config.mstrInstallationVersion; address.strDomainAddress = mResourceDomainServerIp + "/" + Config.mstrInstallationVersion; return(address); }
// 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(); }