Join existing PeerGroup in JXTA/JXSE - java

I have a problem using JXSE.
Let's say i have a rendezVous peer and an Edge peer, not on the same local network.
The rendezVous peer create a peerGroup "test", and publish an advertisement in this group with the name "test advertisement"
Let's say i'm sure than my EdgePeer is connected to the rendezVous peer. I can find the existing group "test" with netpeerGroup.getRemoteAdvertisements().
But i don't know how to join this existing group. I tried netpeergroup.newGroup(testAdv), with testAdv = the founded peerGroupAdvertisement.
I can't find the Advertisement "test advertisement" in the "test" PeerGroup.
But if i do all thats things locally, it works. Maybe i don't understand the difference on how jxta works locally and over internet.
here the code for creating or joining a group :
public void addGroup(final String name) {
ModuleImplAdvertisement mAdv = null;
PeerGroup group = null;
temp = null;
defaultGroup.getDiscoveryService().getRemoteAdvertisements(null, DiscoveryService.GROUP,
"Name", name, 1, new DiscoveryListener() {
#Override
public void discoveryEvent(DiscoveryEvent event) {
Enumeration<Advertisement> advs = event.getResponse().getAdvertisements();
while(advs.hasMoreElements()) {
System.out.println("groupe found");
PeerGroupAdvertisement adv = (PeerGroupAdvertisement) advs.nextElement();
System.out.println("group name : " + adv.getName());
try {
temp = defaultGroup.newGroup(adv);
System.out.println("group joined");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
try {
Thread.sleep(10000);
System.out.println("waiting for group ...");
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if(temp == null) {
try {
System.out.println("creating new group ..");
mAdv = defaultGroup.getAllPurposePeerGroupImplAdvertisement(); /* Getting the advertisement of implemented modules */
temp = defaultGroup.newGroup(generatePeerGroupID(name), mAdv, name, name); /* creating & publishing the group */
getDefaultGroup().getDiscoveryService().remotePublish(temp.getPeerGroupAdvertisement());
} catch (Exception e) {
e.printStackTrace();
}
}

finally found the problem. You had to start the RendezVous service on each groups, and not only the netPeerGroup.
That's why my software works locally but not on internet.

Related

Smack Api Group not working

I am trying to create Group using Smack Api
I use the following code
It crashes on muc#roomconfig_roomowners tag
If i remove that line, it works fine, Group creates
But no group is assigned to the current user, no one is owner
public void createGroup() {
MultiUserChat chatRoom = MultiUserChatManager.getInstanceFor(mConnection).getMultiUserChat("room719#conference." + MYSITE);
try {
chatRoom.create("room719");
Form form = chatRoom.getConfigurationForm().createAnswerForm();
form.setAnswer("muc#roomconfig_publicroom", true);
form.setAnswer("muc#roomconfig_roomname", "room719");
// List owners = new ArrayList();
// owners.add("currUser#"+MYSITE);
form.setAnswer("muc#roomconfig_roomowners", Arrays.asList("currUser#"+MYSITE));
form.setAnswer("muc#roomconfig_persistentroom", true);
chatRoom.sendConfigurationForm(form);
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
This code is working for me, can you try this?
if( !chatRoom.isJoined() ){
chatRoom.createOrJoin("your nickname");
List<String> owners = new ArrayList<String>();
owners.add("currUser#"+MYSITE);
Form form = chatRoom.getConfigurationForm().createAnswerForm();
form.setAnswer("muc#roomconfig_roomname", "your roomname");
form.setAnswer("muc#roomconfig_roomowners", owners);
form.setAnswer("muc#roomconfig_persistentroom", true);
form.setAnswer("muc#roomconfig_publicroom", true);
chatRoom.sendConfigurationForm(form);
}

Error while joining MUC room in XMPP(smack)

I am trying to create a multi user chat. I am getting error while joining the room.
Method for creating chat room :
public void createMultiUserChatRoom(String roomName, String nickName) {
// Get the MultiUserChatManager
MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(connection);
// Get a MultiUserChat using MultiUserChatManager
MultiUserChat multiUserChat = multiUserChatManager.getMultiUserChat(roomName+"#conference.localhost");
try {
multiUserChat.create(nickName);
Form form = multiUserChat.getConfigurationForm();
Form submitForm = form.createAnswerForm();
List<FormField> formFieldList = submitForm.getFields();
for (FormField formField : formFieldList) {
if(!FormField.Type.hidden.equals(formField.getType()) && formField.getVariable() != null) {
submitForm.setDefaultAnswer(formField.getVariable());
}
}
submitForm.setAnswer("muc#roomconfig_persistentroom", true);
submitForm.setAnswer("muc#roomconfig_publicroom", true);
multiUserChat.sendConfigurationForm(submitForm);
} catch (Exception e) {
e.printStackTrace();
}
}
Method for joining MUC room :
public void joinMultiUserChatRoom(String userName, String roomName) {
// Get the MultiUserChatManager
MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(connection);
// Create a MultiUserChat using an XMPPConnection for a room
MultiUserChat multiUserChat = manager.getMultiUserChat(roomName + "#conference.localhost");
DiscussionHistory history = new DiscussionHistory();
history.setMaxStanzas(-1);
try {
multiUserChat.join(userName, "", history, connection.getPacketReplyTimeout());
} catch (Exception e) {
e.printStackTrace();
}
}
Getting list of joined room by user :
public List<String> getJoinedGroupByUserName(String userName) {
// Get the MultiUserChatManager
MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(connection);
List<String> joinedRooms = null;
try {
// Get the rooms where user3#host.org has joined
joinedRooms = manager.getJoinedRooms(userName+"#conference.localhost");
} catch (Exception e) {
e.printStackTrace();
}
return joinedRooms;
}
While user join the room i get this message : "This room is locked from entry until configuration is confirmed."
Room it's not really available (confirmed) after sending a configuration, the creator has to join after
multiUserChat.sendConfigurationForm(submitForm);
so basically creator must also
multiUserChat.join(username)
(if you don't need to stay inside, perform a muc.leave() after a join)

Connect to WinForm server using SignalR?

I have downloaded the official example of SignalR and it works fine when I try to connect from WinFormsClient to WinFormsServer. Everything just fine...
I downloaded the SignalR for android and tried to make a connection using the code below, but no success what so ever...I only get SocketTimeoutException. Here is my code, maybe someone can help me out!
I am trying this on a real device. Both PC and device are on same wifi network.
#Override
public void onClick(View v) {
Platform.loadPlatformComponent(new AndroidPlatformComponent());
String host = "http://192.168.0.11:8080/signalr";
HubConnection connection = new HubConnection(host);
HubProxy proxy = connection.createHubProxy("MyHub");
SignalRFuture<Void> awaitConnection = connection.start();
try {
awaitConnection.get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
proxy.invoke("Send", new String[]{"Hahahahahhahaha", "shit shit shit!"});
proxy.on("AddMessage", new SubscriptionHandler2<String, String>() {
#Override
public void run(String p1, String p2) {
Log.d("result := ", p1 + " ---- " + p2);
}
}, String.class, String.class); }
});
Your firewall may block the connection.

How to get changeset information from tfs using Java tfs-sdk

I tried with the below code
TFSTeamProjectCollection tpc =
new TFSTeamProjectCollection(URIUtils.newURI(COLLECTION_URL), credentials );
VersionControlClient srcctrl = tpc.getVersionControlClient();
Changeset[] chngset;
try {
chngset = srcctrl.queryHistory("http://******/tfs/SpectaTestCollection/", LatestVersionSpec.INSTANCE, 0, RecursionType.FULL, null, new DateVersionSpec("6/10/2014"), LatestVersionSpec.INSTANCE, Integer.MAX_VALUE, false, true, false, true);
for(Changeset ch : chngset)
{
System.out.println("Change Set ID : "+ ch.getChangesetID());
System.out.println("Owner : "+ ch.getOwner());
}
} catch (ServerPathFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
But eveytime getting this error : There is no working folder mapping for D:\WorkSpace\test-workspace\tfsplay.game\http:********\tfs\SpectaTestCollection.
where "D:\WorkSpace\test -workspace\tfsplay.game" is my local workspace.
can anyone help me in guiding to the right way for doing this
Don't pass a URL to the queryHistory method, pass a server path or a local path.
You're getting this error because you have passed a path that is not a server path (does not start with $/), so the system is trying to understand what server path you have mapped to http://...etc. Since that URL is also not a local path, you have gotten that error.
If you want to see all history, pass the server path $/.
public class TestTfsExample {
public static void main(String[] args)
{
Credentials cred=new UsernamePasswordCredentials("username","password") ;
TFSTeamProjectCollection tpc =new TFSTeamProjectCollection(URIUtils.newURI("Application_Collection_url")
, cred);
WorkItemClient workItemClient = tpc.getWorkItemClient();
Changeset[] chngset=null;
LabelSpec lable=new LabelSpec("tfs_start_Label", null);
LabelSpec lable1=new LabelSpec("tfs_end_label", null);
try {
chngset = tpc.getVersionControlClient().queryHistory("$project_directory", LatestVersionSpec.INSTANCE, 0,
RecursionType.FULL, null,new LabelVersionSpec(lable1), new LabelVersionSpec(lable), Integer.MAX_VALUE, true, true, false, true);
} catch (ServerPathFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(Changeset ch : chngset)
{
System.out.println("Change Set ID : "+ ch.getChangesetID());
System.out.println("Owner : "+ ch.getOwner());
Change changes[]=ch.getChanges();
System.out.println("Date : "+ new Date(ch.getDate().getTimeInMillis()));
for(Change chang:changes)
{
System.out.println(chang.getItem().getServerItem());;
//System.out.println("Owner : "+ chang.getItem().getItemType().toString());
}
}
}
}

How restart bluetooth service in bluecove?

I have desktop and android applications, which connected by bluetooth(in desktop side I use Bluecove 2.1.1 library). Desktop application create bluetooth service then android application connects to it. I want to add logout functionality from both desktop and android sides. For example in desktop app user click disconnect, both desktop and android apps reset their connections and should be able to connect again. Here is bluetoothService code for desktop side:
public class BluetoothService
{
private static final String serviceName = "btspp://localhost:"
// + new UUID("0000110100001000800000805F9B34F7", false).toString()
// + new UUID("0000110100001000800000805F9B34F8", false).toString()
+ new UUID("0000110100001000800000805F9B34F9", false).toString()
+ ";name=serviceName";
private StreamConnectionNotifier m_service = null;
private ListenerThread m_listenerThread;
private DataOutputStream m_outStream;
public BluetoothService()
{
Open();
}
public void Open()
{
try
{
assert (m_service == null);
m_service = (StreamConnectionNotifier) Connector.open(serviceName);
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void Start()
{
try
{
StreamConnection connection = (StreamConnection) m_service
.acceptAndOpen();
System.out.println("Connected");
m_listenerThread = new ListenerThread(connection);
Thread listener = new Thread(m_listenerThread);
listener.start();
m_outStream = new DataOutputStream(connection.openOutputStream());
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void Send(String message)
{
assert (m_listenerThread != null);
try
{
m_outStream.writeUTF(message);
m_outStream.flush();
System.out.println("Sent: " + message);
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void Close()
{
try
{
m_service.close();
m_listenerThread.Stop();
m_listenerThread = null;
m_outStream.close();
m_outStream = null;
m_service = null;
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
class ListenerThread implements Runnable
{
private DataInputStream m_inStream;
private boolean m_isRunning;
public ListenerThread(StreamConnection connection)
{
try
{
this.m_inStream = new DataInputStream(connection.openInputStream());
m_isRunning = true;
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
;
}
public void run()
{
while (m_isRunning)
{
try
{
assert (m_inStream != null);
if (m_inStream.available() > 0)
{
String message = m_inStream.readUTF();
System.out.println("Received command: " + message);
CommandManager.getInstance().Parse(message);
}
}
catch (IOException e)
{
System.err.println(e.toString());
}
}
}
public void Stop()
{
m_isRunning = false;
try
{
m_inStream.close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
for restarting service I do:
BluetoothService::Close();
BluetoothService::Open();
BluetoothService::Start();
but seems I cannot reconnect. Maybe I should create service with different name?

Categories

Resources