Created
May 10, 2011 22:24
-
-
Save ibdknox/965499 to your computer and use it in GitHub Desktop.
Socket.IO-netty example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.ibdknox.socket_io_netty.NSIOServer; | |
/********* | |
* git clone [email protected]: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