forked from ringcentral/pubnub-jtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPubnubTestClient.java
More file actions
73 lines (61 loc) · 2.07 KB
/
Copy pathPubnubTestClient.java
File metadata and controls
73 lines (61 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.pubnub.examples;
import java.util.Hashtable;
import com.pubnub.api.*;
public class PubnubTestClient {
Pubnub pubnub;
int recvSuccess;
int recvErrors;
int sendSuccess;
int sendErrors;
PubnubTestClient() {
pubnub = new Pubnub("demo", "demo", "demo", false);
}
public void runTest() {
try {
pubnub.subscribe("TestClientChannel", new Callback() {
@Override
public void successCallback(String channel, Object message) {
recvSuccess++;
}
@Override
public void errorCallback(String channel, PubnubError error) {
recvErrors++;
}
});
} catch (Exception e) {
}
Callback publishCb = new Callback() {
@Override
public void successCallback(String channel, Object message) {
sendSuccess++;
}
@Override
public void errorCallback(String channel, PubnubError error) {
System.out.println(error.toString());
sendErrors++;
}
};
for (int i = 0; i < 10; i++) {
pubnub.publish("TestClientChannel", "Test Client Message", publishCb);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Send Success : " + sendSuccess);
System.out.println("Send Errors : " + sendErrors);
System.out.println("Receive Success : " + recvSuccess);
System.out.println("Receive Errors : " + recvErrors);
}
System.out.println("Send Success : " + sendSuccess);
System.out.println("Send Errors : " + sendErrors);
System.out.println("Receive Success : " + recvSuccess);
System.out.println("Receive Errors : " + recvErrors);
}
/**
* @param args
*/
public static void main(String[] args) {
new PubnubTestClient().runTest();
}
}