Thread: Need help finding Fast Way to send a message to multiple sockets in a list object?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    35

    Need help finding Fast Way to send a message to multiple sockets in a list object?

    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)

    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);
                }
    
    
    
            }
    Is there any other way i can send/recieve messages without it being so delayed sometimes?!
    Last edited by shivam1992; 10-04-2012 at 07:39 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MPI send message
    By mena samy in forum C Programming
    Replies: 5
    Last Post: 03-05-2011, 08:20 AM
  2. Send ACK message
    By daghenningsorbo in forum C Programming
    Replies: 7
    Last Post: 11-07-2009, 12:14 PM
  3. TCP/IP Sockets in C (problem with send() and recv(): how to loop them)
    By ferenczi in forum Networking/Device Communication
    Replies: 3
    Last Post: 11-18-2008, 07:38 AM
  4. is it possible to send a structure using sockets?
    By kopite in forum Networking/Device Communication
    Replies: 7
    Last Post: 12-03-2003, 08:21 AM
  5. how do i send a message from 1 ip to the other ????
    By yorge in forum C++ Programming
    Replies: 4
    Last Post: 04-18-2002, 03:01 PM