PageRenderTime 33ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/socket.io-client/README.md

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
Markdown | 262 lines | 156 code | 106 blank | 0 comment | 0 complexity | b6d730bd027b41b4c1f7545dc5df7dba MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. socket.io
  2. =========
  3. #### Sockets for the rest of us
  4. The `socket.io` client is basically a simple HTTP Socket interface implementation. It allows you to establish a realtime connection with a server (see `socket.io` server [here](http://github.com/LearnBoost/Socket.IO-node)), hiding the complexity of the different transports (WebSocket, Flash, forever iframe, XHR long polling, XHR multipart encoded, etc), while retaining a WebSocket-like API:
  5. socket = new io.Socket('localhost');
  6. socket.connect();
  7. socket.on('connect', function(){
  8. // connected
  9. });
  10. socket.on('message', function(data){
  11. // data here
  12. });
  13. socket.send('some data');
  14. ### Features
  15. - Supports
  16. - WebSocket
  17. - Adobe Flash Socket
  18. - ActiveX HTMLFile (IE)
  19. - XHR with multipart encoding
  20. - XHR with long-polling
  21. - JSONP polling (for cross-domain)
  22. - Tested on
  23. - Safari 4
  24. - Google Chrome 5
  25. - Internet Explorer 6
  26. - Internet Explorer 7
  27. - Internet Explorer 8
  28. - iPhone Safari
  29. - iPad Safari
  30. - Firefox 3
  31. - Firefox 4 (Minefield)
  32. - Opera 10.61
  33. - ActionScript Socket is known not to work behind proxies, as it doesn't have access to the user agent proxy settings to implement the CONNECT HTTP method. If it fails, `socket.io` will try something else.
  34. - On a successful connection, it remembers the transport for next time (stores it in a cookie).
  35. - Small. Closure Compiled with all deps: 5.82kb (gzipped).
  36. - Easy to use! See [socket.io-node](http://github.com/LearnBoost/Socket.IO-node) for the server to connect to.
  37. ### How to use
  38. socket = new io.Socket('localhost');
  39. socket.connect();
  40. socket.send('some data');
  41. socket.on('message', function(data){
  42. alert('got some data' + data);
  43. });
  44. For an example, check out the chat [source](https://github.com/LearnBoost/Socket.IO-node/blob/master/test/chat.html).
  45. ### Notes
  46. If you are serving you .swf from a other domain than socket.io.js you will need to change the WEB_SOCKET_SWF_LOCATION to the insecure version.
  47. <script>WEB_SOCKET_SWF_LOCATION = '/path/to/WebSocketMainInsecure.swf';</script>
  48. The insecure version can be found [here](http://github.com/gimite/web-socket-js/blob/master/WebSocketMainInsecure.zip).
  49. ### Documentation
  50. #### io.Socket
  51. new io.Socket(host, [options]);
  52. ##### Options:
  53. - *secure*
  54. false
  55. Use secure connections
  56. - *port*
  57. Current port or 80
  58. The port `socket.io` server is attached to (defaults to the document.location port).
  59. - *resource*
  60. socket.io
  61. The resource is what allows the `socket.io` server to identify incoming connections by `socket.io` clients. In other words, any HTTP server can implement socket.io and still serve other normal, non-realtime HTTP requests.
  62. - *transports*
  63. ['websocket', 'flashsocket', 'htmlfile', 'xhr-multipart', 'xhr-polling', 'jsonp-polling']
  64. A list of the transports to attempt to utilize (in order of preference).
  65. - *transportOptions*
  66. {
  67. someTransport: {
  68. someOption: true
  69. },
  70. ...
  71. }
  72. An object containing (optional) options to pass to each transport.
  73. - *rememberTransport*
  74. true
  75. A boolean indicating if the utilized transport should be remembered in a cookie.
  76. - *connectTimeout*
  77. 5000
  78. The amount of miliseconds a transport has to create a connection before we consider it timed out.
  79. - *tryTransportsOnConnectTimeout*
  80. true
  81. A boolean indicating if we should try other transports when the connectTimeout occurs.
  82. - *reconnect*
  83. true
  84. A boolean indicating if we should automatically reconnect if a connection is disconnected.
  85. - *reconnectionDelay*
  86. 500
  87. The amount of milliseconds before we try to connect to the server again. We are using a exponential back off algorithm for the following reconnections, on each reconnect attempt this value will get multiplied (500 > 1000 > 2000 > 4000 > 8000).
  88. - *maxReconnectionAttempts*
  89. 10
  90. The amount of attempts should we make using the current transport to connect to the server? After this we will do one final attempt, and re-try with all enabled transport methods before we give up.
  91. ##### Properties:
  92. - *options*
  93. The passed in options combined with the defaults.
  94. - *connected*
  95. Whether the socket is connected or not.
  96. - *connecting*
  97. Whether the socket is connecting or not.
  98. - *reconnecting*
  99. Whether we are reconnecting or not.
  100. - *transport*
  101. The transport instance.
  102. ##### Methods:
  103. - *connect*
  104. Establishes a connection.
  105. - *send(message)*
  106. A string of data to send.
  107. - *disconnect*
  108. Closes the connection.
  109. - *on(event, ?)*
  110. Adds a listener for the event *event*.
  111. - *removeEvent(event, ?)*
  112. Removes the listener ? for the event *event*.
  113. ##### Events:
  114. - *connect*
  115. Fired when the connection is established and the handshake successful.
  116. - *connecting(transport_type)*
  117. Fired when a connection is attempted, passing the transport name.
  118. - *connect_failed*
  119. Fired when the connection timeout occurs after the last connection attempt.
  120. This only fires if the `connectTimeout` option is set.
  121. If the `tryTransportsOnConnectTimeout` option is set, this only fires once all
  122. possible transports have been tried.
  123. - *message(message)*
  124. Fired when a message arrives from the server
  125. - *close*
  126. Fired when the connection is closed. Be careful with using this event, as some transports will fire it even under temporary, expected disconnections (such as XHR-Polling).
  127. - *disconnect*
  128. Fired when the connection is considered disconnected.
  129. - *reconnect(transport_type,reconnectionAttempts)*
  130. Fired when the connection has been re-established. This only fires if the `reconnect` option is set.
  131. - *reconnecting(reconnectionDelay,reconnectionAttempts)*
  132. Fired when a reconnection is attempted, passing the next delay for the next reconnection.
  133. - *reconnect_failed*
  134. Fired when all reconnection attempts have failed and we where unsucessfull in reconnecting to the server.
  135. ### Contributors
  136. Guillermo Rauch &lt;guillermo@learnboost.com&gt;
  137. Arnout Kazemier &lt;info@3rd-eden.com&gt;
  138. ### License
  139. (The MIT License)
  140. Copyright (c) 2010 LearnBoost &lt;dev@learnboost.com&gt;
  141. Permission is hereby granted, free of charge, to any person obtaining
  142. a copy of this software and associated documentation files (the
  143. 'Software'), to deal in the Software without restriction, including
  144. without limitation the rights to use, copy, modify, merge, publish,
  145. distribute, sublicense, and/or sell copies of the Software, and to
  146. permit persons to whom the Software is furnished to do so, subject to
  147. the following conditions:
  148. The above copyright notice and this permission notice shall be
  149. included in all copies or substantial portions of the Software.
  150. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
  151. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  152. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  153. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  154. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  155. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  156. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.