There are: server and client . When the server receives a message in the check_user branch:
private void ProcessReceive(SocketAsyncEventArgs e) {if (e.SocketError == SocketError.Success) {getalltables(); log = new StreamWriter(new FileStream("log.txt", FileMode.Append, FileAccess.Write, FileShare.ReadWrite)); string str = Encoding.UTF8.GetString(e.Buffer, 0, e.BytesTransferred); string[] tmp = str.Split('+'); Console.WriteLine("{2} msg fr C№{0}({3}): {1}", ClientNumber, str, DateTime.Now.TimeOfDay.ToString().Substring(0,10), (Sock.RemoteEndPoint as IPEndPoint).Address); log.Write("\n"); log.Write("{2} Client msg from Client №{0}({3}): {1}\n", ClientNumber, str, DateTime.Now, (Sock.RemoteEndPoint as IPEndPoint).Address); MemoryStream outtabl = new MemoryStream(); switch (tmp[0].Trim()) { case "check_user": this.resp ="check_user"+"+"+checkUser(tmp[1].Trim().ToString()); SendAsync(this.resp); Console.WriteLine("{2} msg to C№{0}({3}): {1}", ClientNumber, "success query " + resp, DateTime.Now.TimeOfDay.ToString().Substring(0, 10), (Sock.RemoteEndPoint as IPEndPoint).Address); log.Write("{2} Message to Client №{0}({3}): {1}", ClientNumber, "success query check_user:", DateTime.Now, (Sock.RemoteEndPoint as IPEndPoint).Address);
how do I send the string "resp" to all clients that are online? (list from ClientConnection) If you try to
foreach(user in onlineusers) { user.sock.SendAsync(this.resp); }
Throws an error:
An asynchronous socket operation is in progress using this SocketAsyncEventArgs instance