/// <summary> /// Starts this instance. /// gets clients in a loop. /// </summary> public void Start() { Console.WriteLine("Starting server on port {0}...", port); IPEndPoint ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port); listener = new TcpListener(ep); // start listening for connections listener.Start(); Console.WriteLine("Waiting for connections..."); //gets the clients Task listeningTask = new Task(() => { while (true) { try { TcpClient c = listener.AcceptTcpClient(); Client client = new Client(c); Console.WriteLine("Got new connection: {0}", client.ToString()); ch.HandleClient(client); } catch (SocketException) { break; } } }); Console.WriteLine("Stating the listening task..."); listeningTask.Start(); listeningTask.Wait(); }
/// <summary> /// starts the server. runs the listener /// </summary> public void Start() { // start listening for incoming clients listener = new TcpListener(ep); listener.Start(); Console.WriteLine("Waiting for connections..."); // the listening task Task task = new Task(() => { while (true) { try { // receive a client and handle it TcpClient client = listener.AcceptTcpClient(); Console.WriteLine("Got new connection"); ch.HandleClient(client); } catch (SocketException) { break; } } Console.WriteLine("Server stopped"); }); // start the listening task task.Start(); task.Wait(); }
/// <summary> /// Starts this instance. The main function. /// </summary> public void Start() { // Define the end point. IPEndPoint ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port); listener = new TcpListener(ep); listener.Start(); Console.WriteLine("Waiting for connections..."); Task task = new Task(() => { // Wait always to clients. while (true) { try { // Listen to Clients and get the connection. TcpClient client = listener.AcceptTcpClient(); Console.WriteLine("Got new connection"); ch.HandleClient(client); } catch (SocketException) { break; } } Console.WriteLine("Server stopped"); }); task.Start(); }
/// <summary> /// Starts this instance. /// </summary> public void Start() { string ip = ConfigurationManager.AppSettings["IP"]; IPEndPoint ep = new IPEndPoint(IPAddress.Parse(ip), port); listener = new TcpListener(ep); listener.Start(); Console.WriteLine("Waiting for connections..."); Task task = new Task(() => { while (true) { try { TcpClient client = listener.AcceptTcpClient(); Console.WriteLine("Got new connection"); ch.HandleClient(client); } catch (SocketException) { break; } } Console.WriteLine("Server stopped"); }); task.Start(); task.Wait(); }
/// <summary> /// Start this instance. /// </summary> public void Start() { IPEndPoint ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port); listener = new TcpListener(ep); listener.Start(); Console.WriteLine("Waiting for connections..."); Task task = new Task(() => { while (true) { try { TcpClient client = listener.AcceptTcpClient(); Console.WriteLine("Got new connection"); ch.HandleClient(client); } catch (SocketException) { //Console.WriteLine("fail"); continue; } } Console.WriteLine("Server stopped"); }); task.Start(); }
public void Start() { listener.Start(); while (true) { try { TcpClient client = listener.AcceptTcpClient(); ch.HandleClient(client); } catch (SocketException) { } } }
/// <summary> /// Starts this instance. /// </summary> public void start() { IPEndPoint ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port); listener = new TcpListener(ep); listener.Start(); Task task = new Task(() => { while (true) { try { TcpClient client = listener.AcceptTcpClient(); ch.HandleClient(client); } catch (SocketException) { break; } } Console.WriteLine("server stopped"); }); task.Start(); }
public void Start() { IPEndPoint ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port); listener = new TcpListener(ep); listener.Start(); Console.WriteLine("Waiting for connections..."); Task task = new Task(() => { Console.WriteLine("$$$$$$#########$$$$$$$#######"); while (true) { Console.WriteLine("3333333333333333333333444444444"); try { Console.WriteLine("9999"); TcpClient client = listener.AcceptTcpClient(); Console.WriteLine("Got new connection"); //Thread.Sleep(86); //break; ch.HandleClient(client); //client.Close(); //break; } catch (SocketException) { Console.WriteLine("xptn"); break; } } Console.WriteLine("---"); }); task.Start(); //task.Wait(); }
/// <summary> /// Start the server. /// </summary> public void Start() { // initialize IPEndPoint ep = new IPEndPoint(IPAddress.Parse(ConfigurationManager.AppSettings[0]), int.Parse(ConfigurationManager.AppSettings[1])); _listener = new TcpListener(ep); _listener.Start(); Console.WriteLine("start get connections"); while (true) { try { // get new connection with client TcpClient client = _listener.AcceptTcpClient(); // give to the client handler to maanage the communication with the client _ch.HandleClient(client); } catch (SocketException) { } } }