[jgroups-dev] JGroup Simplechat application for Android Phones
thisara <[email protected]> Sun, 1 Jun 2014 12:19:40 -0700 (PDT)
| Newsgroups | gmane.comp.java.javagroups.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I'm new to developing. I want to develop JGroup simple chat application in
Android. I'm using Android Developer tool kit to develop the application.
Below are the two classes created in project. One is main activity class and
other one is the simple chat program. I tried to run this application in two
android virtual devices. But it is not working. Highly appreciate if someone
can help me to develop this program.
/package com.example.jgroupan;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Thread(new Runnable() {
@Override
public void run() {
try {
new SimpleChat().start();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it
is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
/
And other class is
/package com.example.jgroupan;
import org.jgroups.ReceiverAdapter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.jgroups.JChannel;
import org.jgroups.Message;
import org.jgroups.ReceiverAdapter;
import org.jgroups.View;
public class SimpleChat extends ReceiverAdapter{
JChannel channel;
String user_name = System.getProperty("user.name", "n/a");
public void start() throws Exception {
System.setProperty("java.net.preferIPv4Stack" , "true");
channel = new JChannel();
channel.setReceiver(this);
channel.connect("chatCluster");
System.out.println("address");
eventLoop();
channel.close();
}
private void eventLoop() {
BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));
while (true) {
try {
System.out.print("> ");
System.out.flush();
String line = in.readLine().toLowerCase();
if (line.startsWith("quit") || line.startsWith("exit")) {
break;
}
line = "[" + user_name + "] " + line;
Message msg = new Message(null, null, line);
channel.send(msg);
} catch (Exception e) {
}
}
}
public void viewAccepted(View new_view) {
System.out.println("** view: " + new_view);
}
public void receive(Message msg) {
System.out.println(msg.getSrc() + ": " + msg.getObject());
}
}
/
--
View this message in context: http://jgroups.1086181.n5.nabble.com/JGroup-Simplechat-application-for-Android-Phones-tp10239.html
Sent from the JGroups - Dev mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Time is money. Stop wasting it! Get your web API in 5 minutes.
www.restlet.com/download
http://p.sf.net/sfu/restlet
_______________________________________________
Javagroups-development mailing list