static void Main(string[] args) { // Declare all variables. string hostname = "127.0.0.1"; int port = 3389; char userInput; // request user input. Console.Write("Type Server(S) or Client(C): "); userInput = Console.ReadLine().ToUpper()[0]; // Store the network type. //networkerType = (userInput == 'S') ? typeof(Server<SocketSession>) : typeof(Client<SocketSession>); string ipAddress = (userInput == 'S' || AddressHelper.CheckIfSamePublic(hostname)) ? AddressHelper.GetLocalAddress() : hostname; if (userInput == 'S') { _networker = NetworkFactory.CreateServer <UnityServerSession>(ipAddress, port); } else { _networker = NetworkFactory.CreateClient <UnityServerSession>(ipAddress, port); } // Bind the networker to the current process. Bind(_networker); // Connect the networker. _networker.Connect(); while (true) { if (_networker is Client <UnityServerSession> && _networker.IsConnected) { ClientSend(); } else { Thread.Sleep(1000); } } _tcpSessionWaitHandler.WaitOne(); }
public static void Main(string[] args) { int port = DefaultPort; if (args.Length == 1) { if (!int.TryParse(args[0], out port)) { Console.Error.WriteLine("Unable to parse port number {0}", args[0]); Console.Error.WriteLine("Using port {0} instead", port); } } NetworkFactory.CreateServer(port, new GameModel()); Console.WriteLine("Server started on {0}:{1}", IPAddress.Any, port); Console.WriteLine("Press any key to stop the server..."); Console.ReadKey(true); Environment.Exit(0); }
/// <summary> /// Create and start a game server. /// </summary> /// <param name="ip">The IP address of the server.</param> /// <param name="tcpPort">The TCP port the server uses.</param> /// <param name="udpPort">The UDP port the server uses.</param> /// <returns>The game server.</returns> public Server CreateServer(string ip, ushort tcpPort, ushort udpPort) { Server = new Server(NetworkFactory.CreateServer(ip, tcpPort, udpPort)); return(Server); }