Skip to main content

How to connect to a specific peer using JxtaSocket?

11 replies [Last post]
ariel_ro
Offline
Joined: 2009-12-28
Points: 0

My question is very simple but it doesn't seem to work for me.

I want to send information using JxtaSocket to a specific peer.

Here's what I got from the javadoc:
public JxtaSocket(PeerGroup group, PeerID peerid, PipeAdvertisement pipeAd,int timeout)
Create a JxtaSocket to any peer listening on pipeAdv this attempts establish a connection to specified pipe within a context of group and within timeout specified

After implementing that I got a very strange warning:
WARNING: Connection response from wrong peer!
urn:jxta:uuid-59616261646162614E504720503250332ED6283ED8284DE484D9B018FFD1474E03 !=urn:jxta:uuid-59616261646162614E504720503250332ED6283ED8284DE484D9B018FFD1474E03

After I receive this, I get a SocketTimeoutException and nothing happens.
It is more than obvious that the above warning is not right since the two peerIds are identic.

Furthermore, I tried connect(PeerGroup group, PeerID peerid, PipeAdvertisement pipeAd, int timeout) method but that doesn't seem to work. I don't get the above exception but I receive a file on more than one host, not only on the one I expect.

I'm using JXSE 2.5

Any help will be highly appreciated!

Message was edited by: ariel_ro

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
adamman71
Offline
Joined: 2007-01-31
Points: 0

I am trying to replicate the issue with the example above. I am tracing the 2.6 code and as far as I can see, the PipeResolver calls ResolverServiceImpl.sendMessage() only once with the provided target peer.

This is not enough to proove that there is no issue, but I need to understand your configuration better.

i) What communication are you using between your peers? Tcp? Multicasting?
ii) Are you using RDVs?

Thanks.

ariel_ro
Offline
Joined: 2009-12-28
Points: 0

First of all I have 2.5.

i) I'm using Tcp along with Unicast
In short, I'm creating a socket server on each peer with the following advertisement:

/**
* Constructs the advertisement of a JxtaServerSocket
*/
public static PipeAdvertisement getSocketAdvertisement() {
PipeID socketID = (PipeID) IDFactory.fromURI(new URI(SocketServerID));
PipeAdvertisement advertisement = (PipeAdvertisement)AdvertisementFactory.newAdvertisement(PipeAdvertisement.getAdvertisementType());

advertisement.setPipeID(socketID);
advertisement.setType(PipeService.UnicastType); // here Unicast is set
advertisement.setName("Socket Server from " + UserValueObject.getUserName());
return advertisement;
}

ii) Absolutely no RDVs implied. Everything is inside the same subnet with ADHOC peers.

P.S: The issue really gave me headaches 2 weeks ago but I managed to get it done with a different socket advertisement per peer. I'm quite sure it's a bug since I tried many, many times and still got nothing...

adamman71
Offline
Joined: 2007-01-31
Points: 0

ADHOC have a 'lazy' kind of participation to peergroup related activities (resolving pipes is one).ADHOCs tend to forward all the queries they get using multicasting, which could explain why all your peers get them. It have to take a deeper look.

adamman71
Offline
Joined: 2007-01-31
Points: 0

I will put an entry in the Wiki FAQ or Known Issues page somewhere down the road...

ariel_ro
Offline
Joined: 2009-12-28
Points: 0

Meanwhile, I realised that I was using the same advertisement and maybe that was the source of error. I changed my code and now it seems to work as expected.

Still, my question remains open. What is peerID parameter from the constructor for?
Is there any kind of precedence, I mean..first comes the group, that the advertisement and than the peerID?

Is it possible for two peers to share the same advertisement for their JxtaServerSocket and be able to connect from a client to a specific one (based on the peerID)?

And the warning is strange at least...how can two identical strings be different? :-??

Any response will be highly appreciated!

adamman71
Offline
Joined: 2007-01-31
Points: 0

About the warning, I think you have put your finger on a bug... The code compares object instances, but not the 'content' (i.e. the ids themselves). I have created a patch on https://jxta-jxse.dev.java.net/issues/show_bug.cgi?id=370. It is committed for 2.6, may be you can apply it on 2.5 locally.

> What is peerID parameter from the constructor for?
It is the Peer ID of the remote peer.

> Is there any kind of precedence, I mean..first comes the group, that the advertisement and than the peerID?
I don't understand the question.

> Is it possible for two peers to share the same advertisement for their JxtaServerSocket and be able to connect from a client to a specific one (based on the peerID)?
Mmmm, good question. I am not sure this will work, though I have not tested it myself. I believe the remote peer who receives the advertisement twice will be confused. I would not rely on this.

Jérôme (AdamMan71)

ariel_ro
Offline
Joined: 2009-12-28
Points: 0

Hi,

Actually I got the source code from JXSE 2.5 and saw for myself that two instances are compared instead of their content. But I blamed it on not having the right build/source code. I couldn't believe that someone could have made such a silly OO related mistake. I wish I could change that and rebuild the project but there were numeros errors in the impl package so I couldn't do anything.

Anyways, to clarify my question about the peerID.

When seeing the constructor of JxtaSocket that contains the peerID [b]and[/b] pipeAdv as parameters I assumed to be able to have the same advertisement for two different JxtaServerSockets and direct the connection to a specific peer.

That is why I asked about precedence. My assumption was that even though the advertisements are the same, the peerID dictates where the other end of the socket binds to. In other words, advertisements have precedence over peerIds.

If the peerID does not direct to a specific peer, than it is useless in that constructor.

adamman71
Offline
Joined: 2007-01-31
Points: 0

It is a pity for the OO compare, I will agree. There has been a lot of code clean-up and refactoring as part of 2.6 (really a lot), and there is still some coming down for 2.7, but we have not pushed it yet, cos it would be a bridge too far.

> When seeing the constructor of JxtaSocket that contains the peerID and pipeAdv as parameters I assumed to be able to have the same advertisement for two different JxtaServerSockets and direct the connection to a specific peer.

If it is a unicast pipe and if you handle this fine (i.e., target peers separately), that should be ok.

ariel_ro
Offline
Joined: 2009-12-28
Points: 0

From what I tested, if I try to connect to a remote peer using the peerID all the ones who have the same advertisement respond. It's like I multicast something instead of unicast it.

I would account this as a bug...but I'm not 100% sure what I do is correct.

adamman71
Offline
Joined: 2007-01-31
Points: 0

Indeed, that would be a bug. I am assuming that you don't define a multicast pipe. I have opened an incident: https://jxta-jxse.dev.java.net/issues/show_bug.cgi?id=371.

ariel_ro
Offline
Joined: 2009-12-28
Points: 0

I'm using JxtaSocket and JxtaServerSocket and the advertisement bound to the serverSocket has the type [i]UnicastType[/i]

Something like: advertisement.setType(PipeService.UnicastType);