Im making a chat application, i already finished it but sometimes the messages are REALLY delayed for some clients. I have two methods, one called checkForMessages that checks the message on the sockets, and sendMessages which sendsthe message to all sockets. I have a list object of sockets that keeps trakc of the connections.
Here is my code for both methods
(this is the server code btw)
Is there any other way i can send/recieve messages without it being so delayed sometimes?!Code:public void checkForMessages(List<Socket> s) { Byte[] byteBuffer = new Byte[1024]; bool result; for (int i = 0; i < s.Count; ++i) { result = s[i].Poll(1000, SelectMode.SelectRead); if (result) { Array.Clear(byteBuffer, 0, byteBuffer.Length); s[i].Receive(byteBuffer); sendMessages(s,byteBuffer); } } } public void sendMessages(List<Socket> s,Byte[] bufferMessage) { for (int i = 0; i < s.Count; ++i) { Socket sendMessage = s[i]; sendMessage.Send(bufferMessage); } }



1Likes
LinkBack URL
About LinkBacks



