1

I am trying to send a set of values (~25) every 200 ms but the project is currently set up in a way that I have to connect to a socket(same port) for each value, send the message and disconnect from it.

It means I connect and disconnect 25 times every 200 ms.

It is possible to have such a high frequency of connections? Is there a limit to this?

here is the pseudo code

func(ByteBuffer packet)
{
-------

if ( packet != null )
    {
        synchronized( tcpClientConnection)
        {
            if ( tcpClientConnection.connect() )
            {
                retval = tcpClientConnection .send( buf );
            }

            tcpClientConnection.disconnect();
        }
    }
-----
}
3
  • 2
    how is the server setup? If it requires a connect/recv/disconnect sequence for each data item, you have no choice. However, if it allows connect/recvall/disconnect, the do what @learningJava suggests Commented Mar 8, 2012 at 18:33
  • You can probably get away with this but I would recommend using MPI. Commented Mar 8, 2012 at 18:56
  • @Mishra Thanks a lot for your suggestion, i will surely look into it Commented Mar 8, 2012 at 19:35

1 Answer 1

1

Try to wrap your connection in what your doing. Something like

class...
   establish connection
   do your work/updates/etc
   disconnect connection

Or you can use simply store all the values you want to update in a local variable and then when your program is done you can upload all the data at once.

Those are the two ways I have been approaching similar problems lately.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks a lot for your quick reply. But, in my case I have a service that generates 25 numbers every 200 ms and these numbers have to be sent at realtime. Problem, this service doesn't stop for weeks or even months.
Is it possible to create process that keeps the connection open and waits for you to give it instructions. If you control the service then you may have to just make sure there are no timeouts. Create x threads that just keep connections open and wait.. Its probably bad programming practice but may get the job done.
I now am opening a connection for a set of values, send it and then disconnect instead of opening and closing for each value. It works well Thanks a lot for your help
cool..glad I could help! Not sure if this helps but recently I learned about pipelining with a database called redis..I think the name might be different between systems but the concept is cool. Basically sends requests to a database without acknowledgment or waiting for response. This allowed me to go from 30,000 connections a second to well over 80,000..This might not be applicable if you want to know when errors occur(a workaround is to log errors on the database itself so the client doesn't need to care)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.