PageRenderTime 26ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/README.markdown

https://bitbucket.org/zealdin/socket.io-java-client
Markdown | 149 lines | 99 code | 50 blank | 0 comment | 0 complexity | 83add879902768a240b16f8268ed640b MD5 | raw file
  1. [![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=Gottox&url=https://github.com/Gottox/socket.io-java-client&title=socket.io-java-client&language=&tags=github&category=software)
  2. # Socket.IO-Client for Java
  3. socket.io-java-client is an easy to use implementation of [socket.io](http://socket.io) for Java.
  4. It uses [Weberknecht](http://code.google.com/p/weberknecht/) as transport backend, but it's easy
  5. to write your own transport. See description below. An XHR-Transport is included, too. But it's
  6. not functional in its current state.
  7. The API is inspired by [java-socket.io.client](https://github.com/benkay/java-socket.io.client).
  8. Features:
  9. * __transparent reconnecting__ - The API cares about re-establishing the connection to the server
  10. when the transport is interrupted.
  11. * __easy to use API__ - implement an interface, instantiate a class - you're done.
  12. * __output buffer__ - send data while the transport is still connecting. No problem, socket.io-java-client handles that.
  13. * __meaningful exceptions__ - If something goes wrong, SocketIO tries to throw meaningful exceptions with hints for fixing.
  14. __Status:__ Connecting with Websocket is production ready. XHR is in beta.
  15. ## How to use
  16. Using socket.io-java-client is quite simple. But lets see:
  17. Checkout and compile the project:
  18. ``` bash
  19. git clone git://github.com/Gottox/socket.io-java-client.git
  20. cd socket.io-java-client
  21. ant jar
  22. mv jar/socketio.jar /path/to/your/libs/project
  23. ```
  24. If you're using ant, change your build.xml to include socketio.jar. If you're eclipse, add the jar to your project buildpath.
  25. Afterwards, you'll be able to use this library:
  26. ``` java
  27. SocketIO socket = new SocketIO("http://127.0.0.1:3001/");
  28. socket.connect(new IOCallback() {
  29. @Override
  30. public void onMessage(JSONObject json, IOAcknowledge ack) {
  31. try {
  32. System.out.println("Server said:" + json.toString(2));
  33. } catch (JSONException e) {
  34. e.printStackTrace();
  35. }
  36. }
  37. @Override
  38. public void onMessage(String data, IOAcknowledge ack) {
  39. System.out.println("Server said: " + data);
  40. }
  41. @Override
  42. public void onError(SocketIOException socketIOException) {
  43. System.out.println("an Error occured");
  44. socketIOException.printStackTrace();
  45. }
  46. @Override
  47. public void onDisconnect() {
  48. System.out.println("Connection terminated.");
  49. }
  50. @Override
  51. public void onConnect() {
  52. System.out.println("Connection established");
  53. }
  54. @Override
  55. public void on(String event, IOAcknowledge ack, Object... args) {
  56. System.out.println("Server triggered event '" + event + "'");
  57. }
  58. });
  59. // This line is cached until the connection is establisched.
  60. socket.send("Hello Server!");
  61. ```
  62. For further informations, read the [Javadoc](http://s01.de/hgexport/socket.io-java-client/).
  63. * [Class SocketIO](http://s01.de/~tox/socket.io-java-client/io/socket/SocketIO.html)
  64. * [Interface IOCallback](http://s01.de/~tox/socket.io-java-client/io/socket/IOCallback.html)
  65. ## Checkout
  66. * with git
  67. git clone git://github.com/Gottox/socket.io-java-client.git
  68. * with mercurial
  69. hg clone https://bitbucket.org/Gottox/socket.io-java-client
  70. Both repositories are synchronized and up to date.
  71. ## Building
  72. to build a jar-file:
  73. cd $PATH_TO_SOCKETIO_JAVA
  74. ant jar
  75. ls jar/socketio.jar
  76. You'll find the socket.io-jar in jar/socketio.jar
  77. ## Bugs
  78. Please report any bugs feature requests to [the Github issue tracker](https://github.com/Gottox/socket.io-java-client/issues)
  79. ## Frameworks
  80. This Library was designed with portability in mind.
  81. * __Android__ is fully supported.
  82. * __JRE__ is fully supported.
  83. * __GWT__ does not work at the moment, but a port would be possible.
  84. * __Java ME__ does not work at the moment, but a port would be possible.
  85. * ... is there anything else out there?
  86. ## Testing
  87. There comes a JUnit test suite with socket.io-java-client. Currently it's tested with Eclipse.
  88. You need node installed in PATH.
  89. * open the project with eclipse
  90. * open tests/io.socket/AllTests.java
  91. * run it as JUnit4 test.
  92. ## TODO
  93. * Socket.io needs more unit-tests.
  94. * XhrTransport needs to pass all tests.
  95. * If websockets are failing (due to proxy servers e.g.), use XHR automaticly instead.
  96. ## License - the boring stuff...
  97. This library is distributed under MIT Licence.
  98. ## Sounds so interesting...
  99. You'll find further documentation at the [Socket.io-java-client Github Wiki](https://github.com/Gottox/socket.io-java-client/wiki)