private void doStart() { Int32 port = 8888; IPAddress localAddr = IPAddress.Parse("127.0.0.1"); TcpListener serverSocket = new TcpListener(localAddr, port); TcpClient clientSocket = default(TcpClient); Console.WriteLine(" >> " + "Server Started"); serverSocket.Start(); int counter = 0; while (true) { counter += 1; clientSocket = serverSocket.AcceptTcpClient(); Console.WriteLine(" >> " + "Client No:" + Convert.ToString(counter) + " started!"); handleClinet client = new handleClinet(); client.startClient(clientSocket, Convert.ToString(counter)); } }
static async Task Main(string[] args) { TcpClient iterator = default(TcpClient); byte[] bytesFrom = new byte[10025]; Byte[] sendBytes = null; string serverResponse = null; List <Question> dbList; databaseCon tmp = new databaseCon(); string mesaj = "You have 15 seconds for answer."; int contestanter_Number = 5; int count_of_eliminated_clients = 1; int randomQuestion; int max_question_number = 9; byte[] inStream = new byte[10025]; TcpListener serverSocket = new TcpListener(8888); TcpClient clientSocket = default(TcpClient); int counter = 0; int index_for_list = 0; int question_number = 0; int exit_from_loop = 0; handleClinet handleclinet = new handleClinet(); serverSocket.Start(); Console.WriteLine(" >> " + "Server Started"); counter = 0; while (counter < 5) { index_for_list = 0; counter += 1; clientSocket = serverSocket.AcceptTcpClient(); Console.WriteLine(" >> " + "Client No:" + Convert.ToString(counter) + " started!"); handleClinet client = new handleClinet(); client.startClient(clientSocket, Convert.ToString(counter)); int kalanYarismaci = 5 - counter; UsingMethods.cLientNumberForStartingQuiz(ref iterator, ref sendBytes, ref serverResponse, counter, ref index_for_list, ref exit_from_loop, kalanYarismaci); if (exit_from_loop == 1) { index_for_list = 0; UsingMethods.sendMessageForQuizStartToClients(ref iterator, ref sendBytes, ref serverResponse, counter, ref index_for_list); break; } } dbList = tmp.ReadAll(); question_number = 0; while (question_number < 10) { int a = 0; randomQuestion = RandomNumber(0, max_question_number--); serverResponse = dbList.ElementAt(randomQuestion).question; dbList.RemoveAt(randomQuestion); UsingMethods.SendQuestiontoClients(ref iterator, ref sendBytes, serverResponse, mesaj, ref contestanter_Number, ref count_of_eliminated_clients, ref a); Thread.Sleep(200); if (ClientHandler.clients.Count == 1) { iterator = ClientHandler.clients.ElementAt(0); serverResponse = "You won. Congrulations.."; NetworkStream networkStream = iterator.GetStream(); sendBytes = Encoding.ASCII.GetBytes(serverResponse); networkStream.Write(sendBytes, 0, sendBytes.Length); Thread.Sleep(200); networkStream.Flush(); goto Son; } Thread.Sleep(18000); question_number++; } Son :; Console.WriteLine("Quiz is over."); clientSocket.Close(); serverSocket.Stop(); Console.WriteLine(" >> " + "exit"); Console.ReadLine(); }
static void Main(string[] args) { TcpListener serverSocket = new TcpListener(2207); TcpClient clientSocket = default(TcpClient); int counter = 0; serverSocket.Start(); Console.WriteLine(" >> " + "Server Started"); while (true) { counter += 1; clientSocket = serverSocket.AcceptTcpClient(); Console.WriteLine(" >> " + "Client No:" + Convert.ToString(counter) + " started!"); handleClinet client = new handleClinet(); client.startClient(clientSocket, Convert.ToString(counter)); } clientSocket.Close(); serverSocket.Stop(); Console.WriteLine(" >> " + "exit"); Console.ReadLine(); }