IEnumerator RunClient() { UnityEngine.Debug.Log("starting client thread"); _client = new ClientThread(); _client.Start(); yield return(null); }
public MainForm(ClientThread manager) { this.Manager = manager; InitializeComponent(); connectionStatus = new System.Timers.Timer(1000); connectionStatus.Elapsed += Connection_Elapsed; onlineCheckTimer = new System.Timers.Timer(5000); onlineCheckTimer.Elapsed += OnlineCheckTimer_Elapsed; ConfigManager = new Common.Config.Manager(); Manager.ClientListener.OnHostInitalizeConnected += (object sender, Common.EventArgs.Network.Client.HostInitalizeConnectedEventArgs e) => { Network.Messages.Connection.Request.HostConnectionMessage ms = new Network.Messages.Connection.Request.HostConnectionMessage(); ms.HostSystemId = e.HostSystemId; ms.ClientSystemId = e.ClientSystemId; ms.Password = Manager.Manager.Encode(e.HostSystemId, this.txtPassword.Text); ms.SymmetricKey = Manager.Manager.Encode(e.HostSystemId, Manager.Manager.getSymmetricKeyForRemoteId(e.HostSystemId)); Manager.Manager.sendMessage(ms); }; Manager.ClientListener.OnClientConnected += OnClientConnected; Manager.ClientListener.onNetworkError += ClientListener_onNetworkError; Manager.ClientListener.onPeerConnected += ClientListener_onPeerConnected; Manager.ClientListener.onPeerDisconnected += ClientListener_onPeerDisconnected; Manager.ClientListener.OnOnlineCheckReceived += ClientListener_OnOnlineCheckReceived; Manager.Start(); }
static void Main(string[] args) { // process cmd line // -prs <PRS IP address>:<PRS port> // create the session table SessionTable sessionTable = new SessionTable(); // get the listening port from the PRS for the "SD Server" service string serviceName = "SD Server"; string prsIP = "127.0.0.1"; ushort prsPort = 30000; PRSServiceClient.prsAddress = IPAddress.Parse(prsIP); PRSServiceClient.prsPort = prsPort; PRSServiceClient prs = new PRSServiceClient(serviceName); ushort listeningPort = prs.RequestPort(); // create the TCP listening socket Socket listeningSocket = new Socket(SocketType.Stream, ProtocolType.Tcp); listeningSocket.Bind(new IPEndPoint(IPAddress.Any, listeningPort)); listeningSocket.Listen(42); // 42 is the number of clients that can be waiting for us to accept their connection Console.WriteLine("Listening for clients on port " + listeningPort.ToString()); bool done = false; while (!done) { // wait for a client to connect Console.WriteLine("Ready to accept new client"); Socket clientSocket = listeningSocket.Accept(); Console.WriteLine("Accepted connection from client"); // create a thread for this client, and then return to listening for more clients Console.WriteLine("Launch new thread for connected client"); ClientThread clientThread = new ClientThread(clientSocket, sessionTable); clientThread.Start(); } // close down the listening socket Console.WriteLine("Closing listening socket"); listeningSocket.Close(); // close the listening port that I received from the PRS prs.ClosePort(); }
protected override void HandleNewConnection(TcpConnection newConnection) { if (newConnection == null) { throw new ArgumentNullException("newConnection"); } RLoginConnection TypedConnection = new RLoginConnection(); if (TypedConnection.Open(newConnection.GetSocket())) { ClientThread NewClientThread = new ClientThread(TypedConnection, _ConnectionType); NewClientThread.Start(); } else { RMLog.Info("Timeout waiting for RLogin header"); TypedConnection.Close(); } }
private void AcceptThreadRun() { while (true) { try { System.Net.Sockets.TcpClient clientSock = serverSocket.AcceptTcpClient(); ClientThread client = new ClientThread(this, clientSock); client.Start(); lock (clients) { clients.Add(client); } } catch (IOException) { } } }
protected override void HandleNewConnection(TcpConnection newConnection) { if (newConnection == null) { throw new ArgumentNullException("newConnection"); } TelnetConnection TypedConnection = new TelnetConnection(); if (TypedConnection.Open(newConnection.GetSocket())) { ClientThread NewClientThread = new ClientThread(TypedConnection, _ConnectionType); NewClientThread.Start(); } else { // TODOX Duplicated code. Maybe add method to base class and call it? RMLog.Info("No carrier detected (probably a portscanner)"); TypedConnection.Close(); } }
protected override void HandleNewConnection(TcpConnection newConnection) { if (newConnection == null) { throw new ArgumentNullException("newConnection"); } WebSocketConnection TypedConnection = new WebSocketConnection(); if (TypedConnection.Open(newConnection.GetSocket())) { // TODOX Start a proxy thread instead of a clientthread ClientThread NewClientThread = new ClientThread(TypedConnection, _ConnectionType); NewClientThread.Start(); } else { RMLog.Info("No carrier detected (probably a portscanner)"); TypedConnection.Close(); } }
static void Main(string[] args) { // process cmd line // -prs <PRS IP address>:<PRS port> try { for (int i = 0; i < args.Length; i++) { if (args[i] == "-prs")// -prs prsip:prsport { if (i++ < args.Length) { string[] parts = args[i].Split(':'); if (parts.Length != 2) { throw new Exception("Invalid PRSIP:PRSAddress format"); } PRS_ADDRESS = parts[1]; PRS_PORT = System.Convert.ToUInt16(parts[0]); } else { throw new Exception("No value for -prs option"); } } else { throw new Exception("Invalid cmdline parameter"); } } }catch (Exception ex) { Console.WriteLine("Error processing command line:" + ex); return; } // create the session table SessionTable sessionTable = new SessionTable(); Console.WriteLine("PRS ADDRESS:" + PRS_ADDRESS); Console.WriteLine("PRS PORT:" + PRS_PORT); // get the listening port from the PRS for the "SD Server" service PRSClient PRS = new PRSClient(IPAddress.Parse(PRS_ADDRESS), PRS_PORT, SERVICE_NAME); ushort listeningPort = PRS.RequestPort(); // create the TCP listening socket Socket listeningSocket = new Socket(SocketType.Stream, ProtocolType.Tcp); listeningSocket.Bind(new IPEndPoint(IPAddress.Any, listeningPort)); listeningSocket.Listen(CLIENT_BACKLOG); // 42 is the number of clients that can be waiting for us to accept their connection Console.WriteLine("Listening for clients on port " + listeningPort.ToString()); bool done = false; while (!done) { // wait for a client to connect Console.WriteLine("Ready to accept new client"); Socket clientSocket = listeningSocket.Accept(); Console.WriteLine("Accepted connection from client"); // create a thread for this client, and then return to listening for more clients Console.WriteLine("Launch new thread for connected client"); ClientThread clientThread = new ClientThread(clientSocket, sessionTable); clientThread.Start(); } // close down the listening socket Console.WriteLine("Closing listening socket"); listeningSocket.Close(); // close the listening port that I received from the PRS PRS.ClosePort(); }
public override void ViewDidLoad() { base.ViewDidLoad(); Manager.Start(); }
private void Listen() { this.server.Listen(10); while (this.isRun) { Socket client = this.server.Accept(); client.Blocking = true; ClientThread thread = new ClientThread(this, client); thread.OnReceive += this.OnReceive; thread.OnDisconnect += this.OnDisconnect; this.clients.Clear(); this.clients.Add(thread); if (this.OnConnect != null) { this.OnConnect(this, new SocketEventArgs(client)); } thread.Start(); } }
protected override void Execute() { using (TcpConnection Connection = new TcpConnection()) { if (Connection.Listen(_LocalAddress, _LocalPort)) { RaiseBoundEvent(); while (!_Stop) { // Accept an incoming connection if (Connection.CanAccept(1000)) // 1 second { try { TcpConnection NewConnection = Connection.AcceptTCP(); if (NewConnection != null) { TcpConnection TypedConnection = null; switch (_ConnectionType) { case ConnectionType.RLogin: TypedConnection = new RLoginConnection(); break; case ConnectionType.Telnet: TypedConnection = new TelnetConnection(); break; case ConnectionType.WebSocket: TypedConnection = new WebSocketConnection(); break; } if (TypedConnection != null) { TypedConnection.Open(NewConnection.GetSocket()); if (IsIgnoredIP(TypedConnection.GetRemoteIP())) { // Do nothing for ignored IPs TypedConnection.Close(); } else { RaiseMessageEvent("Incoming " + _ConnectionType.ToString() + " connection from " + TypedConnection.GetRemoteIP() + ":" + TypedConnection.GetRemotePort()); TerminalType TT = GetTerminalType(TypedConnection); if (IsBannedIP(TypedConnection.GetRemoteIP())) { DisplayAnsi("IP_BANNED", TypedConnection, TT); RaiseWarningMessageEvent("IP " + TypedConnection.GetRemoteIP() + " matches banned IP filter"); TypedConnection.Close(); } else if (_Paused) { DisplayAnsi("SERVER_PAUSED", TypedConnection, TT); TypedConnection.Close(); } else { if (!TypedConnection.Connected) { RaiseMessageEvent("No carrier detected (maybe it was a 'ping'?)"); TypedConnection.Close(); } else { ClientThread NewClientThread = new ClientThread(); int NewNode = RaiseConnectEvent(ref NewClientThread); if (NewNode == 0) { NewClientThread.Dispose(); DisplayAnsi("SERVER_BUSY", TypedConnection, TT); TypedConnection.Close(); } else { NewClientThread.Start(NewNode, TypedConnection, _ConnectionType, TT); } } } } } } } catch (Exception ex) { RaiseExceptionEvent("Error in ServerThread::Execute()", ex); } } } } else { RaiseErrorMessageEvent("Server Thread unable to listen on " + _LocalAddress + ":" + _LocalPort); RaiseBindFailedEvent(); } } }
static void Main(string[] args) { ushort listeningPort = 40001; string serviceName = "FT Server"; string prsIP = "127.0.0.1"; // TODO: get prsIP from the cmdline ushort prsPort = 30000; // TODO: process cmd line // -prs <PRS IP address>:<PRS port> // -p listening port if (args != null)//if we have command line options { string[] command = args; if ((command.Length) % 2 != 0)//if each command doesnt have a { throw (new Exception("Invalid Command Line Args")); } for (int i = 0; i < command.Length; i = i + 2) { switch (command[i].ToLower()) { case "-prs": //prs command gotten string[] ipportstring = command[i + 1].Split(':'); prsIP = ipportstring[0]; prsPort = Convert.ToUInt16(ipportstring[1]); break; case "-p": //port to listen on listeningPort = Convert.ToUInt16(command[i + 1]); break; default: break; } } } // get the listening port from the PRS for the "FT Server" service // TODO: get prsPort from the cmdline PRSServiceClient.prsAddress = IPAddress.Parse(prsIP); PRSServiceClient.prsPort = prsPort; PRSServiceClient prs = new PRSServiceClient(serviceName); listeningPort = prs.RequestPort(); // create the TCP listening socket Socket listeningSocket = new Socket(SocketType.Stream, ProtocolType.Tcp); listeningSocket.Bind(new IPEndPoint(IPAddress.Any, listeningPort)); listeningSocket.Listen(42); // 42 is the number of clients that can be waiting for us to accept their connection Console.WriteLine("Listening for clients on port " + listeningPort.ToString()); bool done = false; while (!done) { // wait for a client to connect Console.WriteLine("Ready to accept new client"); Socket clientSocket = listeningSocket.Accept(); Console.WriteLine("Accepted connection from client"); // TODO: worry about keep alives to the PRS for our FT Server port number // create a thread for this client, and then return to listening for more clients Console.WriteLine("Launch new thread for connected client"); ClientThread clientThread = new ClientThread(clientSocket); clientThread.Start(); } // close down the listening socket Console.WriteLine("Closing listening socket"); listeningSocket.Close(); // close the listening port that I received from the PRS prs.ClosePort(); }