× 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.



> Everything works really well, except that after the second or third (I
> think) rendition of the socket listener spawning a new job the whole
> thing just kind of hangs as if the sockets are all used up.  Now...using
> Scott's design,  I spawn about 10 socket instances from the single
> socket listener and from there as each spawned job finishes, I terminate
> the program and the main socket listener spawns another socket, reusing
> that now closed socket port.
> And, as I say, it works fine for awhile, but at some point it all just
> hangs. To "fix" this, I end the socket jobs and restart them.  Then
> everything works fine again for awhile, until, once again it hangs.

If you change the backlog parameter to the listen() API, does it have any
affect on how quickly the "hang" happens?

Are you remembering to close the socket in your instance program before it
ends?


> I'm wondering if the sockets ports are really being freed up like I
> think they are or if something else is going on.

The port is not supposed to be "freed up" until the listener program ends.
In most applications, the listener should remain running all the time, it
should not be closed unless you take it down for maintenance or something
like that.  (Or, perhaps you only want services to be available at certain
times of the day, or whatever...)

But, it does kind of sound like you're hitting the number of connections
allowed on the port at a time.   This would imply that you're not closing
the sockets, or that they're lingering for a long time.   You control the
number of connections allowed on the port at a given time by setting the
"backlog" parameter of the listen() API.

Also, if you want your applications to be robust, make sure you're using
non-blocking sockets.   There are little timing errors that can cause a
blocking socket to get stuck waiting indefinitely.  For a robust
application, you should ALWAYS use non-blocking.

Of course, there are lots of reasons why a program can get "hung up."  It
might be helpful if you told us what the program is doing when it stops
responding, what statement it's executing, etc.

If this does turn out to be a bug in the code that I have posted in the
tutorial, please let me know about it so that I can correct it.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
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.