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



Last week I mentioned some 'flaky-ness' with a socket server program.
This is a multi-connection socket server, and I determined that the
reason the connections weren't behaving as expected was because I
wasn't using non-blocking mode. Hence the program appeared to 'hang'
while waiting to receive data.

What do you mean by "multi-connection"? I typically write my servers
using one of three different models:

a) Spawning Server -- spawns (or submits) a new job for each new
connection. (the FTP server and TELNET server on i5/OS are examples of
this.)

b) Handoff Server -- Uses a pool of active jobs to handle each new
connection. Every time a new connection is made, it's handed off to the
next available job in the active job pool. (The HTTP server on i5/OS is
an example of this.)

c) Multiplexing Server -- A single job handles multiple simultaneous
connections by using the select() API to determine which ones are
readable or writable, and switching between them. This is often used
for proxies, chat applications or games... any time you need all of the
sockets to be able to communicate with one another.

Answer1 - I'm using option C - the multiplexing server model.

In my attempt to correct this problem I added code to set the socket
to non-blocked mode. In doing so, I found that after accepting a
connection (which is always 'up'), even though no data is currently
being sent (data will come as it becomes available), I exit my socket
read/write loop, without dropping the socket connection and return to
the outer loop which (I thought) should enable me to check for
incoming data on another connection (ie server shutdown request).

That sounds like a multiplexing server.

Answer2 - Agreed.

in doing this I found (via netstat *cnn) that multiple remote ports
(from the same remote client) are connecting to the socket server.

The server doesn't control that. That's controlled by the client
program -- the client side is using multiple sockets, and calling the
connect() API on each one. (Possibly by running multiple copies of the
same program, or possibly the client program is giving up and starting a
new connection without properly closing the previous one.)

Answer3 - I was wondering too if that was possibly the case. Thanks for
confirming that suspicion. Unfortunately my network guy is gone until
Tuesday and he has to contact the remote client's network person who is in
Connecticut (who's a consultant for the remote client who is in Michigan).
So it won't be until some time next week before I can get that question
into their inbox (whether the client is giving up and starting a new
connection without properly closing the previous one).

As a side note, my listen function is set to one, although I suspect
it should be set to two, so that it can listen to the remote client,
and also listen for a shutdown request from a different source (the
local iSeries).

In a multiplexing server model, I would set the backlog parameter of the
listen() API to the same number as the number of sockets your program
can handle at once. So I would expect this to be larger than 2!!

Answer4 - I have it set to 3. One for the remote client, one to accept a
server shutdown at my request (1/month for system save/go save #21), and
one for my desktop utility that I can use to emulate the remote client
(but this third connection is only for testing and will never be used once
we're in a production environment).

In a handoff model, I typically set this to about five times as many as
I have worker jobs, figuring the others can queue up and wait, since
handoff servers typically don't take long to finish their transactions.

In a spawn model, I just set it to a high number...


But as it is now, it will shut down while connected
to the remote client and I connect locally to issue the shutdown
request with the listen value set to one.

I don't follow this. Why would the listener shut down if you're
handling multiple sockets at once. It sounds like this is designed to
handle only one connection at a time from this description...

Answer5 - refer to my previous response (Answer4) regarding the backlog
parm. For now we will have only one remote connection, but my intent was
to enable this program to support more connections should we be requested
to support additional service providers in the future. (And if this turns
out to not be a practical idea then I suspect I can just clone this
program to support the additional providers.)

So this morning I changed the listen value to two, shut down and
restarted and things appeared to be okay for 2.5 hours (only one
connection from the remote client showing in netstat), but when I
got back from lunch I now see two connections on different ports from
the same IP address. The remote should only be establishing one
connection should only be sending on one port.

This is happening because the client is connecting more than once. It's
possible (depending on how the software works) that you're doing
something to trigger the client to do this -- but that would mean that
there's code in the client designed to reconnect based on some event.
Without knowing more about that scenario, I can't tell you what's
causing it. I'd have to know how the client works.

Answer6 - I don't think I'm doing anything to cause this (emphasis on
'don't think' - but there I go thinking again:) since I'm not dropping the
socket connection when there isn't any data received. I did test that
(dropping the socket) and did see *IMMED that new connections were being
created. So this then sounds very similar to the issues discussed at
Answer3.

In a typical scenario, however, a server program can't cause this to
happen. Only the client can.

Answer7 - I'll bring this up to the network people next week. Hopefully
they'll have some input on this.

In the meantime, THANKS AGAIN for your input Scott. Over the last three
years we've implemented four different socket client applications all of
which run nonstop and unfailingly - thanks to you.

Enjoy the holiday!

Regards, Jerry

Gerald Kern - MIS Project Leader
Lotus Notes/Domino Administrator
IBM Certified RPG IV Developer
The Toledo Clinic, Inc.
4235 Secor Road
Toledo, OH 43623-4299
Phone 419-479-5535
gkern@xxxxxxxxxxxxxxxx


This e-mail message, including any attachments, is for the sole use of the
intended recipient(s) and may contain confidential and privileged
information. Any unauthorized use, disclosure or distribution is
prohibited. If you are not the intended recipient, please inform the
sender by reply e-mail and destroy this and all copies of this message.

As an Amazon Associate we earn from qualifying purchases.

This thread ...


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.