You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlrpc-dev@ws.apache.org by Paul Guyot <pg...@kallisys.net> on 2003/05/12 21:36:21 UTC

Random port for WebServer

Hi all,

I'm designing a software that is supposed to be replicated several 
times on the network and possibly several times on the same machine.
For that reason, I pass 0 as the port of WebServer and I override the 
class to access the serverSocket on which I call getLocalPort() to 
get the actual port and advertise it so instances can find each other.

Still, it sounds like a hack, it is based on the source code and I 
wonder if this use could be legitimated with:
- a documented constructor taking no port
- an accessor on the port which would ask the server socket (or 
retrieve it from the member variable that would get updated when the 
server socket is instantiated) -- actually, unless one comes with a 
subclass that accesses it, the WebServer class does not use its port 
member variable.

Any thought? May I submit a patch for these changes?

Paul
-- 
NPDS: http://newton.kallisys.net:8080/
Apache: http://www.kallisys.com/

Re: Random port for WebServer

Posted by Paul Guyot <pg...@kallisys.net>.
Il me semble que le 12/5/03 à 15:42 -0400, Ryan Hoegg nous racontait:
>I wouldn't mind a patch with testcases.
>
>Keep in mind that new features are targetted for 2.0, so grab CVS 
>HEAD and do it there.
>
>I am not convinced about whether this belongs in WebServer or a 
>derived class, any opinions?

The random port is chosen by the JVM in the ServerSocket class:

>public ServerSocket(int port)
>              throws IOException
>
>     Creates a server socket, bound to the specified port. A port of 
>0 creates a socket on any free port.

AFAIK, the ServerSocket instance is created in WebServer, unless one 
derives it.

OK, it was more complex than it with 1.1 because the server is not 
started from the constructor.

Patch file (against CVS HEAD) is attached. I've added a test for this 
new feature and documented the thing. The WebServer test seems to 
pass.

By "seems to pass", I mean that I get 
"java.util.NoSuchElementException" for every request I send to the 
server. But I also get this on an unpatched version of xml-rpc.

The jar works fine in my application (in OS X, I'm going to test it 
on Solaris in a minute). Since I forgot to add start() at first, I 
even tested this feature. I don't get the NoSuchElementException line 
with my application.

BTW, I'm not extremely familiar with ant to say the least, but to be 
able to compile the project, I had to add a line to build.xml to 
accept commons-codec.jar in the class path. The patch includes this 
as well.

Paul

Re: Random port for WebServer

Posted by Ryan Hoegg <rh...@isisnetworks.net>.
I wouldn't mind a patch with testcases.

Keep in mind that new features are targetted for 2.0, so grab CVS HEAD 
and do it there.

I am not convinced about whether this belongs in WebServer or a derived 
class, any opinions?

--
Ryan Hoegg
ISIS Networks
http://www.isisnetworks.net

Paul Guyot wrote:

> Hi all,
>
> I'm designing a software that is supposed to be replicated several 
> times on the network and possibly several times on the same machine.
> For that reason, I pass 0 as the port of WebServer and I override the 
> class to access the serverSocket on which I call getLocalPort() to get 
> the actual port and advertise it so instances can find each other.
>
> Still, it sounds like a hack, it is based on the source code and I 
> wonder if this use could be legitimated with:
> - a documented constructor taking no port
> - an accessor on the port which would ask the server socket (or 
> retrieve it from the member variable that would get updated when the 
> server socket is instantiated) -- actually, unless one comes with a 
> subclass that accesses it, the WebServer class does not use its port 
> member variable.
>
> Any thought? May I submit a patch for these changes?
>
> Paul