private static void Main(string[] arg) { Global.NetworkPID = Actor.SpawnNamed(Actor.FromProducer(() => new NetworkActor()), "Network"); Global.RoomPID = Actor.SpawnNamed(Actor.FromProducer(() => new RoomActor()), "Room"); try { var quit = false; var handler = new ConsoleCmdHandler(); handler.OnCmd = async args => { switch (args[0]) { case "q": quit = true; break; } }; while (!quit) { handler.Update(); Thread.Sleep(10); } } catch (Exception e) { LoggerUtil.Fatal(typeof(Program), e.ToString()); } Global.RoomPID.Stop(); Global.NetworkPID.Stop(); LoggerUtil.Info(typeof(Program), "server exited"); }
private static void Main(string[] arg) { try { SyncScene scene = null; var quit = false; var handler = new ConsoleCmdHandler(); LoggerUtil.Info(typeof(Program), "client inited"); using (var cli = new UDPNetworkMT()) { cli.Trace = true; cli.OnConnect = () => LoggerUtil.Info(typeof(Program), "connected"); cli.OnDisconnect = () => LoggerUtil.Info(typeof(Program), "disconnected"); cli.OnReceive = (bytes, channelId) => LoggerUtil.Info(typeof(Program), "recv: " + Encoding.ASCII.GetString(bytes)); handler.OnCmd = args => { switch (args[0]) { case "c": cli.Connect("127.0.0.1", 1234); break; case "q": cli.Disconnect(); quit = true; break; case "dc": cli.Disconnect(); break; case "p": cli.Pause = !cli.Pause; LoggerUtil.Info(typeof(Program), "pause:{0}", cli.Pause); break; default: var cmd = string.Join(" ", args); if (cmd.StartsWith("`")) { cli.Send(Encoding.ASCII.GetBytes(cmd.Remove(0, 1))); } break; } }; while (!quit) { handler.Update(); cli.Update(); Thread.Sleep(100); } } } catch (Exception e) { LoggerUtil.Fatal(typeof(Program), e.ToString()); } LoggerUtil.Info(typeof(Program), "client exited"); }