Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Net.Sockets;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- public class Server
- {
- IPAddress ipAd;
- bool running = false;
- public Server()
- {
- }
- public IPAddress IpAd { get => ipAd; set {
- if (running) ipAd = value;
- else throw new Exception("Server is running. You can't change the IP address.");
- } }
- public void server()
- {
- try
- {
- ipAd = IPAddress.Parse("127.0.0.1");
- TcpListener myList = new TcpListener(IpAd, 8001);
- myList.Start();
- running = true;
- Console.WriteLine("The server is running at port 8001");
- Console.WriteLine("Local end point: " +
- myList.LocalEndpoint);
- Console.WriteLine("Waiting for a connection...");
- while (true)
- {
- TcpClient client = myList.AcceptTcpClient();
- if(client != null)
- {
- Console.WriteLine("Client connected!");
- }
- ThreadPool.QueueUserWorkItem(IO.ClientThread.ThreadProc, client);
- System.Threading.Thread.Sleep(1000);
- }
- }
- catch (Exception e)
- {
- Console.WriteLine("Error... " + e.StackTrace);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement