Skip to content

Commit

Permalink
yunba connect event
Browse files Browse the repository at this point in the history
  • Loading branch information
tigerzhang committed Apr 14, 2014
1 parent 65a72bc commit cda91b9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,2 +1,4 @@
bin/
jar/
.idea
BasicExample.class
8 changes: 8 additions & 0 deletions README.markdown
Expand Up @@ -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:
Expand Down
20 changes: 16 additions & 4 deletions examples/basic/BasicExample.java
Expand Up @@ -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");
}
}
12 changes: 12 additions & 0 deletions socket.io-java-client.iml
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

0 comments on commit cda91b9

Please sign in to comment.