static void Main(string[] args) { // Set working directory to application directory. // Otherwise Windows/System32 is used. Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory; try { XmlConfigurator.Configure(); Console.WriteLine("Loaded app.config"); } catch (Exception) { Console.WriteLine("Error: configuration file not found."); throw; } try { MessageDispatcher md = new MessageDispatcher(); md.RegisterHandlers(new Program()); ClientListener server = new ClientListener(3333, new SocketListener(), md); server.Start(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void OnJoinGameResult(object sender, ClientListener <JoinGameMessage> .TArg e) { //Получение позиции игрока в игре uint?myPlayerPosition = e.Arg.MyPosition; //Проверка позиции игрока if (myPlayerPosition == null) { //Если присоединение не удалось, то разрываем соединение OnJoin?.Invoke(null); tcpClient.Dispose(); return; } //Если присоединение успешно OnJoin?.Invoke(e.Arg); //Если есть противник, то начинаем игру if (e.Arg.EnemyName != null) { joinGameListener.Stop(); OnStart?.Invoke(); playGameListener.Start(); } }
private void ListenClient() { client_listener = new ClientListener(this, ServerSettings.BindAddr, ServerSettings.BindPort, _logger); client_listener.OnClientsChange += Client_listener_OnClientsChange; client_listener.Start(); _logger.LogDebug($"监听客户端 -> {ServerSettings.BindAddr}:{ServerSettings.BindPort}"); }
private void StartClient() { Client.OnStatusUpdate += OnStatusUpdate; Client.OnReceive += OnReceive; Client.Start("127.0.0.1", 3000); Client.Send(new MangalysProtocol.Messages.BasicInfoMessage(Environment.MachineName, Environment.UserName)); }
private void buttonStart_Click(object sender, EventArgs e) { ClientListener listener; listener = new ClientListener(new IPEndPoint(GetLocalInternalIP(), UInt16.Parse(textBoxLocalPort.Text)), new IPEndPoint(IPAddress.Parse(textBoxRemoteIp.Text), UInt16.Parse(textBoxPort.Text)), ProxyMode); Listener.OnGotResultsCbk onGotRes = new Listener.OnGotResultsCbk(OnGotResults); listener.SetOnGotResults(onGotRes); listenerList.Add(listener); listener.Start(); }
private static void Main(string[] args) { // Available Parameters (at the moment): // port: expected number var parameters = ArgsHelper.GetParams(args); ServerListener server = new ServerListener(); if (!server.Start(parameters["port"])) { Console.WriteLine(":: Zero Chat Lite v1.0 ::"); Console.WriteLine("Welcome to the chat room! To exit just type '/exit'"); ClientListener client = new ClientListener(); client.Start(parameters["port"]); } }
private void JoinGame(string playerName) { if (!tcpClient.Connected) { OnJoin?.Invoke(null); return; } try { //Отправка имени игрока: TextMessage textMessage = new TextMessage(playerName); tcpClient.Send(textMessage); joinGameListener.Start(); } catch (Exception) { OnJoin?.Invoke(null); } }
public void Start(int port) { if (Running) { throw new InvalidOperationException("Server already running"); } try { Process.GetCurrentProcess().PriorityClass = ServerBasePriority; }catch (Exception ex) { ISLogger.Write("Cannot set process priority to {0}: {1}", ServerBasePriority, ex.Message); } ConnectedClient.LocalHost = new ConnectedClient(true); ISLogger.Write("Starting server..."); ServerPort = port; clientMan = new ClientManager(ServerDefaultMaxClients); clientMan.AddClient(ConnectedClient.LocalHost); tcpListener = new ClientListener(); tcpListener.ClientConnected += TcpListener_ClientConnected; tcpListener.Start(port); SetConsoleText("Current client: localhost"); //We need to determine which OS is being used OSHelper.Os os = OSHelper.GetOsVersion(); switch (os.System) { case OSHelper.Platform.Windows: { inputMan = new WindowsInputManager(); curMonitor = new WindowsCursorMonitor(); outManager = new WindowsOutputManager(); procMonitor = new WindowsProcessMonitor(); break; } default: throw new NotImplementedException(); } inputMan.Start(); curMonitor.Start(); curMonitor.EdgeHit += LocalHost_EdgeHit; procMonitor.StartMonitoring(); procMonitor.ProcessEnteredFullscreen += ProcMonitor_ProcessEnteredFullscreen; procMonitor.ProcessExitedFullscreen += ProcMonitor_ProcessExitedFullscreen; Running = true; inputMan.InputReceived += InputMan_InputReceived; inputMan.ClientHotkeyPressed += InputMan_ClientHotkeyPressed; inputMan.FunctionHotkeyPressed += InputMan_FunctionHotkeyPressed; inputMan.ClipboardTextCopied += InputMan_ClipboardTextCopied; LoadHotkeySettings(); }