summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorAndrzej J.R. Hunt <andrzej@ahunt.org>2012-08-02 16:11:06 +0200
committerMichael Meeks <michael.meeks@suse.com>2012-08-06 10:23:08 +0100
commit341f89ec308bd5a66a36741d22f100721d8223de (patch)
tree1e0f279550384817a31df246b57a8524f11179d5 /android
parente43e36facc93b9e27e4d8757124ca0e6fcd9396b (diff)
Early non-functional multicast code.
Change-Id: Id982b40e5e9df4dee037a2e54ed34206930123c9
Diffstat (limited to 'android')
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/TestClient.java3
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java2
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java104
3 files changed, 108 insertions, 1 deletions
diff --git a/android/sdremote/src/org/libreoffice/impressremote/TestClient.java b/android/sdremote/src/org/libreoffice/impressremote/TestClient.java
index ee8c57b68b96..dc74cd527f65 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/TestClient.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/TestClient.java
@@ -85,7 +85,8 @@ public class TestClient extends Activity {
mCommunicationService = ((CommunicationService.CBinder) aService)
.getService();
mCommunicationService.connectTo(
- CommunicationService.Protocol.NETWORK, "10.0.2.2");
+ CommunicationService.Protocol.NETWORK,
+ "192.168.0.18");
mCommunicationService.setActivityMessenger(mMessenger);
enableButtons(true);
}
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
index 258bff1b26be..e1669cc8497c 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
@@ -55,6 +55,8 @@ public class CommunicationService extends Service {
@Override
public void onCreate() {
// TODO Create a notification (if configured).
+ ServerFinder aFinder = new ServerFinder();
+ aFinder.startFinding();
}
@Override
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java b/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java
new file mode 100644
index 000000000000..d787e3478f1c
--- /dev/null
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java
@@ -0,0 +1,104 @@
+package org.libreoffice.impressremote.communication;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.SocketException;
+
+public class ServerFinder {
+
+ private static final int PORT = 1598;
+ private static final String CHARSET = "UTF-8";
+
+ private DatagramSocket mSocket = null;
+
+ private Thread mListenerThread = null;
+
+ public ServerFinder() {
+
+ }
+
+ private void listenForServer() {
+ byte[] aBuffer = new byte[500];
+ DatagramPacket aPacket = new DatagramPacket(aBuffer, aBuffer.length);
+
+ try {
+ String aCommand = null;
+ String aAddress = null;
+ System.out.println("SF:listening for packet\n");
+ mSocket.receive(aPacket);
+ System.out.println("SF:received packet\n");
+ int i;
+ for (i = 0; i < aBuffer.length; i++) {
+ if (aPacket.getData()[i] == '\n') {
+ aCommand = new String(aPacket.getData(), 0, i, CHARSET);
+ break;
+ }
+ }
+ if (i == aBuffer.length || !aCommand.equals("LOREMOTE_ADVERTISE")) {
+ return;
+ }
+
+ for (int j = i + 1; j < aBuffer.length; j++) {
+ if (aPacket.getData()[j] == '\n') {
+ aAddress = new String(aPacket.getData(), i + 1, j, CHARSET);
+ }
+ }
+
+ if (aAddress != null) {
+ System.out.println("Address is :" + aAddress + "\n");
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ public void startFinding() {
+ if (mSocket != null)
+ return;
+
+ if (mListenerThread == null) {
+ mListenerThread = new Thread() {
+ @Override
+ public void run() {
+ try {
+ mSocket = new DatagramSocket();
+ String aString = "LOREMOTE_SEARCH\n";
+ DatagramPacket aPacket = new DatagramPacket(
+ aString.getBytes(CHARSET),
+ aString.length(),
+ InetAddress.getByName("239.0.0.1"),
+ PORT);
+ mSocket.send(aPacket);
+ System.out.println("SF:sent packet\n");
+ while (true) {
+ listenForServer();
+ }
+ } catch (SocketException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (UnsupportedEncodingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+ };
+ mListenerThread.start();
+ }
+
+ }
+
+ public void stopFinding() {
+ if (mListenerThread != null) {
+
+ }
+ }
+}