Simulatneous Socket Send/Recv

Hi Forum.

I am currently programming an application with a TCP socket interface to another system. The interface must:

1) send and receive a keep-alive message every 10 seconds
2) receive messages and send responses
3) send messages after an event occurs in the program

Currently I am using Asynchronous sockets with select with two separate threads.

One thread handles the keep-alive sending/receiving and also and messages received from the other system. The socket has been programmed to block on recv for 10 seconds, which will then escape and send a keep-alive message. Any request messages are received, processed and responded to here.

The other thread monitors external sensors and will send messages to the other system based events triggered by sensors.

It seems as though i'm really overcomplicating things, particularly using asynchronous sockets. Is there an easier way of structuring this?

Is it advisable to use the same socket for everything? I'm guessing the current setup will cause problems as it will try and send a message while the same socket is simultaneously listening for messages.

I have thought about using another thread for sending (as kind of a message queue), but that would still require sending while receiving.

Many thanks,
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!