private void mainServerThread() { while (true) { clientSocket = serverSocket.AcceptTcpClient(); MainFunctions.ConsoleWrite(" Client connected!", ConsoleColor.White); byte[] handshake = new byte[512]; int bytes = clientSocket.GetStream().Read(handshake, 0, handshake.Length); Clients client = new Clients(); client.usrName = Encoding.GetEncoding("windows-1250").GetString(handshake, 0, bytes); for (int i = 0; i < 128; i++) { if (idExists(i) == false) { client.uID = i; break; } } client.startClientThread(clientSocket); clientList.Add(client); MainFunctions.ConsoleWrite(String.Format(" New Client, ID: {0}, Name: {1}, Count: {2}", client.uID, client.usrName, clientList.Count)); } }
public static void sendClientData(byte[] buffer, int size, Clients sender) { foreach (Clients client in core.clientList) { if (client != sender) { client.sendDataToClient(buffer, size, sender); } } }
public bool sendDataToClient(byte[] buffer, int size, Clients sender) { if (isConnected() == false) return false; if (this != sender) { NetworkStream nStream = clientSocket.GetStream(); nStream.Write(buffer, 0, size); nStream.Flush(); } return true; }