Skip to content

Commit 2752238

Browse files
committed
updated for compatability with meteor 0.5.7 DDP spec
1 parent 18851ec commit 2752238

File tree

3 files changed

+75
-3
lines changed

3 files changed

+75
-3
lines changed

src/me/kutrumbos/DdpClient.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ public class DdpClient extends Observable {
2323
private final WebSocketClient wsClient;
2424
private final Gson gson = new Gson();
2525

26+
private final static String DDP_PROTOCOL_VERSION = "pre1";
27+
2628
/**
2729
* Field names supported in the DDP protocol
2830
*
2931
*/
3032
public enum DdpMessageField {
31-
MSG("msg"), ID("id"), METHOD("method"), PARAMS("params"), NAME("name"), SERVER_ID("server_id");
33+
MSG("msg"), ID("id"), METHOD("method"), PARAMS("params"), NAME("name"), SERVER_ID("server_id"),
34+
SESSION("session"), VERSION("version"), SUPPORT("support");
3235

3336
private String fieldId;
3437

@@ -86,6 +89,8 @@ private void connectionOpened() {
8689
System.out.println("WebSocket connection opened");
8790
Map<DdpMessageField,Object> connectMsg = new HashMap<DdpMessageField,Object>();
8891
connectMsg.put(DdpMessageField.MSG, "connect");
92+
connectMsg.put(DdpMessageField.VERSION, DDP_PROTOCOL_VERSION);
93+
connectMsg.put(DdpMessageField.SUPPORT, new String[]{DDP_PROTOCOL_VERSION});
8994
send(connectMsg);
9095
}
9196

src/me/kutrumbos/examples/DdpClientExample.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package me.kutrumbos.examples;
22

33
import java.net.URISyntaxException;
4+
import java.util.Date;
45
import java.util.Observer;
56

67
import me.kutrumbos.DdpClient;
@@ -32,11 +33,26 @@ public static void main(String[] args) {
3233

3334
// make connection to Meteor server
3435
ddp.connect();
36+
37+
while(true) {
38+
try {
39+
Thread.sleep(5000);
40+
41+
System.out.println("calling remote method...");
42+
43+
Object[] methodArgs = new Object[1];
44+
methodArgs[0] = new Date().toString();
45+
ddp.call("update_time", methodArgs);
46+
47+
} catch (InterruptedException e) {
48+
49+
e.printStackTrace();
50+
}
51+
}
3552

3653
} catch (URISyntaxException e) {
3754
e.printStackTrace();
38-
}
39-
55+
}
4056
}
4157

4258

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package me.kutrumbos.examples;
2+
3+
import java.net.URISyntaxException;
4+
import java.util.Observer;
5+
6+
import me.kutrumbos.DdpClient;
7+
8+
/**
9+
* Simple example of DDP client use-case that just involves
10+
* making a connection to a locally hosted Meteor server
11+
* @author peterkutrumbos
12+
*
13+
*/
14+
public class DdpMultiClientTestExample {
15+
16+
public static void main(String[] args) {
17+
18+
// specify location of Meteor server (assumes it is running locally)
19+
String meteorIp = "localhost";
20+
Integer meteorPort = 3000;
21+
22+
try {
23+
24+
// create DDP client instance
25+
DdpClient ddp = new DdpClient(meteorIp, meteorPort);
26+
27+
// create DDP client observer
28+
Observer obs = new SimpleDdpClientObserver();
29+
30+
// add observer
31+
ddp.addObserver(obs);
32+
33+
// make connection to Meteor server
34+
ddp.connect();
35+
36+
Thread.sleep(1000);
37+
38+
ddp.subscribe("allPositions", new Object[]{});
39+
40+
} catch (URISyntaxException e) {
41+
e.printStackTrace();
42+
} catch (InterruptedException e) {
43+
// TODO Auto-generated catch block
44+
e.printStackTrace();
45+
}
46+
47+
}
48+
49+
50+
51+
}

0 commit comments

Comments
 (0)