So I went looking for options to query the OS for a free port and found an 
answer on stackoverflow that I think is simply brilliant.
(I hope it's OK to quote from others here? Apologies if not.)

"If your server was told what port to use, just bind() it. Seriously.

Sure, you could parse /proc/net/tcp and see if the port's in use. But then 
what? You still need to call bind() now that you know your port is free, and 
it'll tell you if the port was free then anyway, and so there was no point in 
groveling through /proc/net/tcp and doing all that (slow!) string production 
and parsing and extra kernel trips through not-very-well-optimized (read: super 
slow compared to bind()) diagnostic paths, just to get information that could 
well be out of date before you even finished parsing it. So just call bind() 
and be happy."

The full article is here for those interested:
http://stackoverflow.com/questions/10294515/how-do-i-find-in-c-that-a-port-is-free-to-use

So back in UV Basic we'd just call initServerSocket with the desired port 
number and action according to success or failure!



Peter Cheney
Ultracs Developer
t 07 3017 8837 | f 07 3002 8400
e peter.che...@firstmac.com.au
w firstmac.com.au


-----Original Message-----
From: u2-users-boun...@listserver.u2ug.org 
[mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of David A. Green
Sent: Wednesday, 5 March 2014 22:35
To: 'U2 Users List'
Subject: Re: [U2] Multi-threaded phantom processing

I don't know how you would query the OS on the fly, but you can do a manual 
search for a bank of 10 or 20 unused ports and "claim" them.

David A. Green
(480) 201-7953
DAG Consulting

-----Original Message-----
From: u2-users-boun...@listserver.u2ug.org 
[mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of Peter Cheney
Sent: Tuesday, March 04, 2014 9:30 PM
To: 'U2 Users List'
Subject: Re: [U2] Multi-threaded phantom processing

Thanks David. As they say "Bigger than Ben-Hur"!

That's a great idea. The server I have is listening on a predetermined port. I 
trolled through /etc/services and a netstat on the remote host to select 
something that looked unused.

So then if it the main phantom spawns 1-n children (presumably more phantoms?), 
it would also need to select 1-n ports which I suppose must also be 
predetermined? Or is there a call to the OS that can return an unused port? 
We're on AIX but the remote host is HPUX.

Cheers
Peter



Peter Cheney
Ultracs Developer
t 07 3017 8837 | f 07 3002 8400
e peter.che...@firstmac.com.au
w firstmac.com.au


_______________________________________________
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users

 -------------------------------------------------------------------------------
Note: 
This email (inc all attachments) is for the use of the intended recipient(s) 
only.
Privileged or confidential information may be contained in this communication. 
If you have received this email in error, please notify the sender immediately 
and then delete all copies of this message from your computer network. If you 
are not the intended recipient, you must not keep, use, disclose, copy or 
distribute this email without the author's prior permission. If you are the 
intended recipient and you do not wish to receive similar electronic messages 
from us in future, then please respond to the sender to this effect. 
We have taken precautions to minimise the risk of transmitting software 
viruses, but advise you to carry out your own virus checks on this email and 
its attachments. We do not accept liability for any loss or damage caused by 
software viruses and do not represent that this transmission is free from 
viruses or other defects. 
Firstmac Limited (ABN 59 094 145 963) (AFSL 290600) 
 -------------------------------------------------------------------------------
_______________________________________________
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users

Reply via email to