Skip to main content

Programmatic Port Configuration

8 replies [Last post]
levere
Offline
Joined: 2005-11-04
Points: 0

I'm trying to create a JXTA program that bypasses the configuration GUI and initializes the JXTA platform programmatically. The only issue I haven't been able to solve is that of port configuration. How do I go about programmatically changing the default incoming connection port from 9701 to one of my own choosing?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
johndickerson
Offline
Joined: 2006-01-20
Points: 0

Hi,

myjxta (http://myjxta2.jxta.org) uses ext:config for programatic configuration of peers.

Regards

John Dickerson

alexhealing
Offline
Joined: 2005-11-01
Points: 0

It does seem strange.

There is an 'attribute name="range"' in the profile under TransportAddress which specifies a port range. I haven't tried anything yet but I suppose it could be possible that this specifies incoming port ranges(?)

Also, if you haven't seen this already: http://wiki.java.net/bin/view/Jxta/ExtConfig

levere
Offline
Joined: 2005-11-04
Points: 0

Yeah, I tried playing around with that attribute. It is, in fact, a range value and has no affect on which port the range begins.

haestrup
Offline
Joined: 2005-11-12
Points: 0

Try something like this.

------------ code ------------
TcpTransport tcp; // your tcptransport

TcpTransportAddress tcpaddr = new TcpTransportAddress();
String addr = Util.getLocalHost();
String port = "9701";

tcpaddr.setAddress(new URI("tcp://" + addr + ":" + port));
tcpaddr.setPortRange(0);
tcp.setAddress(tcpaddr);
------------ code ------------

You say that the port is the only thing you are having trouble with. I myself have trouble with just recreating the default gui Platform file. Maybe you have some inputs for me.

If I generate a Platform file with the Jxta configurator. Then in another program load() that file and save it again without changing anything the new Platform is different from the gui generated. Is that strange or what..

haestrup
Offline
Joined: 2005-11-12
Points: 0

Allow me just to comment on my own reply.

I succeded in creating a configuration that I could use. Its not the same as the one generated by the GUI but it gets my program working.
I have found that the best way to get what you want is to make a xml file that states your preferences. You use that xml file to create a Profile that you pass onto the configuration. Like this:
Profile pro = new Profile(new FileInputStream("myconf.xml"));
Configuration conf = new Configuration(pro);
conf.save();

There are some stubs for the profile xml file in the source . Look for edge.xml, seed.xml, proto.xml
They should get you started. I found looking at the xml schema in the Javadoc of the Profile class handy aswell.

As a treat for this thread you can also specify the port in this file.

johndickerson
Offline
Joined: 2006-01-20
Points: 0

I have looked at edge.xml, seed.xml, proto.xml and looked at the schema for these files in the javadoc of net.jxta.ext.config.Profile.

To create my own profile.xml reliably, I need a proper schema. The schema in the Javadoc is incomplete. I found a schema somewhere on the net but when I opened it in XmlSpy the schema itself was invalid.

I think the schema needs changing so that it is more intuitive and compliant. A compliant schema needs hosting somewhere so we can readily download it and validate our profile.xml files against it.

Does anyone know whether I am right about the schema not being compliant ?

Also does anyone know where I can down a compliant schema so that I can validate my own profile files against it ?

It seems to me, that it is not overly intuitive trying to programatically create configurations for testing multiple peers on one machine. Does anyone know of any helper classes that make this job easier ?

I was thinking that if I can suss it out myself I might create the helper classes and wrap them up in custom Ant tasks to enable starting multiple peers on one machine.

Any one done this yet ?

Thanks

Regards

John Dickerson

Anyone

alexhealing
Offline
Joined: 2005-11-01
Points: 0

The only information I've found about bypassing the GUI is here: http://www-128.ibm.com/developerworks/java/library/j-jxta2/ - scroll down to: 'Programming JXTA configuration for a silent startup'. Let me know how you get on or if you have any more information on this please.

levere
Offline
Joined: 2005-11-04
Points: 0

I already checked out that article but thanks anyway. Several of the 'Configurator' interfaces used in the code block don't seem to exist in the current version of JXTA. I didn't have much luck trying to update the code myself. I had more success with this example:

http://www.tbray.org/ongoing/When/200x/2005/09/01/Just-Enough-JXTA

It uses a profile XML file to initialize JXTA but unless I am missing something, it doesn't allow you to configure the incoming connection port.

You can view the XML schema for the profile XML file here:

http://platform.jxta.org/nonav/java/impl/index.html

Click on 'Profile'.