× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




I have a process that uses sockets to send day to an outside vendor.
Basically this process receives a request via a dtaq.  It then
sends/receives the msg to the vendor via a sockets. Then sends the
response to another dtaq to be used by another process.  It actually load
balances between two persistent socket connections.   I have always
controlled the sending and receiving, including a network message that
functions as a keepalive.   Now the vendor want to be able to send
unsolicited network messages to my process.

I'm not sure that "unsolicited" is really the right word, but I think I understand what you mean. The vendor wants to be able to send you data an an arbitrary point in time, and your problem is that your program can only receive data when it's in a particular state -- it's not continually monitoring the socket for data.


I am not sure how to handle this. Will I have to use a select() to see if I need to receive a message before I try to send?

What makes this so difficult is the data queues. You can't simultaneously wait on both data queues and sockets. You have to wait on one or the other.

Here are your options:

a) You share the same socket across two jobs. One job waits for input from the socket, the other job only writes to the socket, and waits for input on the data queue. That way, one job is waiting on the data queue most of the time, and the other job is waiting on the socket most of the time.

b) You write a loop that checks the data queue (with a timeout of 0), then checks the socket (with a timeout of perhaps 1/4 second), and keeps looping. (You use the select() API to check the socket). This'll use more CPU time, but the 1/4 second timeout on the socket should prevent it from going too crazy on CPU time. The big disadvantage, however, is that if there's data on the data queue, it may have to wait for 1/4 second before being read.

Since you mention load balancing, it sounds to me like you're working with a high volume, and therefore 1/4 second delay might be very serious.

If you could eliminate the data queues and do it all with sockets, then select() could be used to handle it all in one program. I suppose you could have the data queues be read in a separate program in a separate job, and have it take the data queue data and send it via socket to the program that communicates with the vendor. Then that vendor communication program could sit in select() loop and handle both sockets without delays.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.