Jump to content
  • Advertisement
Sign in to follow this  
vivendi

Socket question

This topic is 3475 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, we are currently programming a async socket connection with C#. I have a quick question. The socket doesn't always seem to be sending the data right away. So my question is, how do i have to initialise the socket to make sure that whenever i want to send a string, no matter how small, that it sends it right away. This is currently how we do it: Small socket class:
        public class SocketPacket
        {
            // Constructor neemt een socket en een client nummer
            public SocketPacket(System.Net.Sockets.Socket socket, int clientNumber)
            {
                m_currentSocket = socket;
                m_clientNumber = clientNumber;
            }
            public System.Net.Sockets.Socket m_currentSocket;
            public int m_clientNumber;

            // Buffer om de data op te slaan die gestuurd wordt door de client.
            public byte[] dataBuffer = new byte[1024];
        }
And this is how we initialise the socket:
m_mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
And this is how i currently send it:
            // Convert de data naar een byte array
            byte[] byData = System.Text.Encoding.ASCII.GetBytes(msg);

            Socket workerSocket = (Socket)m_workerSocketList[clientNumber - 1];
            workerSocket.Send(byData);
This is the server part. Which is continously sending data. But i'm not sure if it's building up data first before sending, or if it's sending data right away. And that is what we want. It should send strings right away.

Share this post


Link to post
Share on other sites
Advertisement
Disable Nagle.

Despite that, there is no option to send *right now*. It's still up to network stack to decide when to send, but that is usually good enough, especially if you're not exceeding bandwidth capacity. But that's a problem of limited resources.

Generally, UDP is preferred for this type of tasks. As long as you're using TCP, if any of packets get lost, receiver will be waiting for resends, so regardless of how fast one sends, there will be a minimum of round-trip delay when receiving.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!