summaryrefslogtreecommitdiff
path: root/same-android/src/main/java
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-06 20:56:20 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-06 20:56:20 +0100
commit8d19516ef4a2983f343883c29a48eacd942040ec (patch)
tree0600cae4b3953af9bca6f9266edc69474e6e4276 /same-android/src/main/java
parenta803c9d86341355f3ea9bf823abbbd07cb64283e (diff)
Fix same-android.
– Use new Configuration class. – Enter MasterService url manually.
Diffstat (limited to 'same-android/src/main/java')
-rw-r--r--same-android/src/main/java/com/orbekk/HelloAndroidActivity.java4
-rw-r--r--same-android/src/main/java/com/orbekk/discovery/SameService.java33
2 files changed, 21 insertions, 16 deletions
diff --git a/same-android/src/main/java/com/orbekk/HelloAndroidActivity.java b/same-android/src/main/java/com/orbekk/HelloAndroidActivity.java
index e27f941..090d719 100644
--- a/same-android/src/main/java/com/orbekk/HelloAndroidActivity.java
+++ b/same-android/src/main/java/com/orbekk/HelloAndroidActivity.java
@@ -31,7 +31,7 @@ public class HelloAndroidActivity extends Activity {
intent.setAction("join");
// InetAddress address = new Broadcaster(this).getBroadcastAddress();
EditText t = (EditText)findViewById(R.id.editText1);
- intent.putExtra("ip", t.getText().toString());
+ intent.putExtra("masterUrl", t.getText().toString());
startService(intent);
}
@@ -61,7 +61,7 @@ public class HelloAndroidActivity extends Activity {
setContentView(R.layout.main);
showIpAddress();
- showBroadcastAddress();
+ // showBroadcastAddress();
// ClientApp client = new ClientApp();
// SameInterface client_ = client.getClient(10015, "ClientNetwork",
diff --git a/same-android/src/main/java/com/orbekk/discovery/SameService.java b/same-android/src/main/java/com/orbekk/discovery/SameService.java
index 0dd6593..900c7c8 100644
--- a/same-android/src/main/java/com/orbekk/discovery/SameService.java
+++ b/same-android/src/main/java/com/orbekk/discovery/SameService.java
@@ -3,6 +3,7 @@ package com.orbekk.discovery;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.util.Properties;
import android.app.Service;
import android.content.Intent;
@@ -14,17 +15,18 @@ import android.widget.Toast;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.orbekk.same.ClientApp;
import com.orbekk.same.DiscoveryListener;
-import com.orbekk.same.MasterApp;
import com.orbekk.same.NetworkNotificationListener;
import com.orbekk.same.SameController;
+import com.orbekk.same.config.Configuration;
public class SameService extends Service {
final static int PORT = 15066;
+ final static int SERVICE_PORT = 15068;
private Logger logger = LoggerFactory.getLogger(getClass());
private Thread discoveryThread = null;
private SameController sameController = null;
+ private Configuration configuration = null;
public final class DiscoveryThread extends Thread {
Broadcaster broadcast;
@@ -81,6 +83,15 @@ public class SameService extends Service {
}
}
+ private void initializeConfiguration() {
+ Properties properties = new Properties();
+ properties.setProperty("port", ""+SERVICE_PORT);
+ properties.setProperty("localIp",
+ new Broadcaster(this).getWlanAddress().getHostAddress());
+ properties.setProperty("masterUrl", "http://10.0.0.6:10010/MasterService.json");
+ configuration = new Configuration(properties);
+ }
+
private void sendBroadcastDiscovery(InetAddress ip) {
Broadcaster broadcaster = new Broadcaster(this);
String message = "Discover " + (PORT + 2);
@@ -96,7 +107,7 @@ public class SameService extends Service {
}
}
- private void joinNetwork(InetAddress ip) {
+ private void searchNetworks(InetAddress ip) {
sameController.getClient().setNetworkListener(
new NetworkNotificationListener() {
@Override
@@ -121,27 +132,21 @@ public class SameService extends Service {
Toast.makeText(this, "service start: " + intent.getAction(),
Toast.LENGTH_SHORT).show();
if (sameController == null) {
- sameController = SameController.create(PORT + 2);
+ initializeConfiguration();
+ sameController = SameController.create(configuration);
try {
sameController.start();
- String myIp = new Broadcaster(this).getWlanAddress()
- .getHostAddress();
- String myUrl = "http://" + myIp + ":" + (PORT + 2) + "/";
- sameController.setUrl(myUrl);
} catch (Exception e) {
logger.error("Failed to start server", e);
return START_STICKY;
}
}
+
if (intent.getAction().equals("create")) {
createNetwork();
} else if (intent.getAction().equals("join")) {
- try {
- InetAddress ip = InetAddress.getByName(intent.getExtras().getString("ip"));
- joinNetwork(ip);
- } catch (UnknownHostException e) {
- logger.error("Unknown host.", e);
- }
+ String masterUrl = intent.getExtras().getString("masterUrl");
+ sameController.joinNetwork(masterUrl);
}
return START_STICKY;
}