netty-demo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.9 KiB

13 years ago
13 years ago
13 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
13 years ago
  1. #Overview
  2. This project is an open-source Java implementation of [Socket.IO](http://socket.io/) server. Based on [Netty](http://netty.io/) server framework.
  3. Required JDK 1.5 (or above).
  4. Licensed under the Apache License 2.0.
  5. ### Features
  6. * Supports 0.7+ version of [Socket.IO-client](https://github.com/LearnBoost/socket.io-client) up to latest - 0.9.6
  7. * Supports xhr-polling transport
  8. * Supports websocket transport (Hixie-75/76/Hybi-00, Hybi-10..Hybi-13)
  9. #Usage example
  10. ##Server
  11. SocketIOListener handler = new SocketIOListener() {
  12. @Override
  13. public void onMessage(SocketIOClient client, String message) {
  14. ...
  15. }
  16. @Override
  17. public void onDisconnect(SocketIOClient client) {
  18. ...
  19. }
  20. @Override
  21. public void onConnect(final SocketIOClient client) {
  22. ...
  23. }
  24. @Override
  25. public void onJsonObject(SocketIOClient client, Object obj) {
  26. ...
  27. SampleObject obj = new SampleObject();
  28. // send object to socket.io client
  29. client.sendJsonObject(obj);
  30. }
  31. };
  32. Configuration config = new Configuration();
  33. config.setHostname("localhost");
  34. config.setPort(81);
  35. config.setListener(handler);
  36. SocketIOServer server = new SocketIOServer(config);
  37. server.start();
  38. ...
  39. server.stop();
  40. ##Client
  41. <script type="text/javascript" src="socket.io.js" charset="utf-8"></script>
  42. <script type="text/javascript">
  43. var socket = io.connect('http://localhost:81', {
  44. 'reconnection delay' : 2000,
  45. 'force new connection' : true
  46. });
  47. socket.on('message', function(data) {
  48. // here is your handler on messages from server
  49. });
  50. socket.on('connect', function() {
  51. // connection established, now we can send an objects
  52. // send json-object to server
  53. var obj = ...
  54. socket.json.send(obj);
  55. });
  56. </script>