Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Socket.IO-netty example
import com.ibdknox.socket_io_netty.INSIOClient;
import com.ibdknox.socket_io_netty.INSIOHandler;
public class EchoHandler implements INSIOHandler {
@Override
public void OnConnect(INSIOClient client) {
System.out.println("A user connected :: " + client.getSessionID());
}
@Override
public void OnDisconnect(INSIOClient client) {
System.out.println("A user disconnected :: " + client.getSessionID() + " :: hope it was fun");
}
@Override
public void OnMessage(INSIOClient client, String message) {
System.out.println("Got a message :: " + message + " :: echoing it back to :: " + client.getSessionID());
client.send(message);
}
@Override
public void OnShutdown() {
//useful if you're keeping a list of connected users (you probably will be)
//this would be where you would disconnect all of them and do any clean up you
//need to do.
}
}
import com.ibdknox.socket_io_netty.NSIOServer;
/*********
* git clone git@github.com:ibdknox/socket.io-netty.git
* mvn package
*
* Add netty and socket-io-netty.jar as dependencies.
* Or you can just add the uber-socket-io-netty.jar if you're not using netty for anything else.
*
* @author chris
*
*/
public class EchoServer {
public static void main(String[] args) {
NSIOServer echo = new NSIOServer(new EchoHandler(), 8083);
echo.start();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.