diff --git a/.gitignore b/.gitignore index d1b29c6..e0c7e85 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ bin/ jar/ +.idea +BasicExample.class diff --git a/README.markdown b/README.markdown index f946202..b74ce07 100644 --- a/README.markdown +++ b/README.markdown @@ -34,6 +34,14 @@ ant jar mv jar/socketio.jar /path/to/your/libs/project ``` +### Try Yunba Example + +```bash +cd examples +javac -cp ../jar/socketio.jar basic/BasicExample.java +java -cp ../jar/socketio.jar:. basic.BasicExample +``` + If you're using ant, change your build.xml to include socketio.jar. If you're eclipse, add the jar to your project buildpath. Afterwards, you'll be able to use this library: diff --git a/examples/basic/BasicExample.java b/examples/basic/BasicExample.java index 6f01917..bc98aea 100644 --- a/examples/basic/BasicExample.java +++ b/examples/basic/BasicExample.java @@ -77,13 +77,25 @@ public void onConnect() { @Override public void on(String event, IOAcknowledge ack, Object... args) { System.out.println("Server triggered event '" + event + "'"); - if (event.equals("socketconnectack")) { - onSocketConnectAck(); - } + try { + if (event.equals("socketconnectack")) { + onSocketConnectAck(); + } else if (event.equals("connack")) { + onConnAck(); + } + } catch (Exception e) { + e.printStackTrace(); + } } - public void onSocketConnectAck() { + public void onSocketConnectAck() throws Exception { System.out.println("onSocketConnectAck"); // emit connect + + socket.emit("connect", new JSONObject("{'appkey': '52fcc04c4dc903d66d6f8f92'}")); } + + public void onConnAck() { + System.out.println("onConnAck"); + } } diff --git a/socket.io-java-client.iml b/socket.io-java-client.iml new file mode 100644 index 0000000..d5c0743 --- /dev/null +++ b/socket.io-java-client.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + +