Ein Projekt das es ermöglicht Beerpong über das Internet von zwei unabhängigen positionen aus zu spielen. Entstehung im Rahmen einer Praktikumsaufgabe im Fach Interaktion.
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.

README.md 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. # ws: a node.js websocket library
  2. [![Build Status](https://travis-ci.org/einaros/ws.svg?branch=master)](https://travis-ci.org/einaros/ws)
  3. `ws` is a simple to use WebSocket implementation, up-to-date against RFC-6455,
  4. and [probably the fastest WebSocket library for node.js][archive].
  5. Passes the quite extensive Autobahn test suite. See http://einaros.github.com/ws
  6. for the full reports.
  7. ## Protocol support
  8. * **Hixie draft 76** (Old and deprecated, but still in use by Safari and Opera.
  9. Added to ws version 0.4.2, but server only. Can be disabled by setting the
  10. `disableHixie` option to true.)
  11. * **HyBi drafts 07-12** (Use the option `protocolVersion: 8`)
  12. * **HyBi drafts 13-17** (Current default, alternatively option `protocolVersion: 13`)
  13. ### Installing
  14. ```
  15. npm install --save ws
  16. ```
  17. ### Sending and receiving text data
  18. ```js
  19. var WebSocket = require('ws');
  20. var ws = new WebSocket('ws://www.host.com/path');
  21. ws.on('open', function open() {
  22. ws.send('something');
  23. });
  24. ws.on('message', function(data, flags) {
  25. // flags.binary will be set if a binary data is received.
  26. // flags.masked will be set if the data was masked.
  27. });
  28. ```
  29. ### Sending binary data
  30. ```js
  31. var WebSocket = require('ws');
  32. var ws = new WebSocket('ws://www.host.com/path');
  33. ws.on('open', function open() {
  34. var array = new Float32Array(5);
  35. for (var i = 0; i < array.length; ++i) {
  36. array[i] = i / 2;
  37. }
  38. ws.send(array, { binary: true, mask: true });
  39. });
  40. ```
  41. Setting `mask`, as done for the send options above, will cause the data to be
  42. masked according to the WebSocket protocol. The same option applies for text
  43. data.
  44. ### Server example
  45. ```js
  46. var WebSocketServer = require('ws').Server
  47. , wss = new WebSocketServer({ port: 8080 });
  48. wss.on('connection', function connection(ws) {
  49. ws.on('message', function incoming(message) {
  50. console.log('received: %s', message);
  51. });
  52. ws.send('something');
  53. });
  54. ```
  55. ### Server sending broadcast data
  56. ```js
  57. var WebSocketServer = require('ws').Server
  58. , wss = new WebSocketServer({ port: 8080 });
  59. wss.broadcast = function broadcast(data) {
  60. wss.clients.forEach(function each(client) {
  61. client.send(data);
  62. });
  63. };
  64. ```
  65. ### Error handling best practices
  66. ```js
  67. // If the WebSocket is closed before the following send is attempted
  68. ws.send('something');
  69. // Errors (both immediate and async write errors) can be detected in an optional
  70. // callback. The callback is also the only way of being notified that data has
  71. // actually been sent.
  72. ws.send('something', function ack(error) {
  73. // if error is not defined, the send has been completed,
  74. // otherwise the error object will indicate what failed.
  75. });
  76. // Immediate errors can also be handled with try/catch-blocks, but **note** that
  77. // since sends are inherently asynchronous, socket write failures will *not* be
  78. // captured when this technique is used.
  79. try { ws.send('something'); }
  80. catch (e) { /* handle error */ }
  81. ```
  82. ### echo.websocket.org demo
  83. ```js
  84. var WebSocket = require('ws');
  85. var ws = new WebSocket('ws://echo.websocket.org/', {
  86. protocolVersion: 8,
  87. origin: 'http://websocket.org'
  88. });
  89. ws.on('open', function open() {
  90. console.log('connected');
  91. ws.send(Date.now().toString(), {mask: true});
  92. });
  93. ws.on('close', function close() {
  94. console.log('disconnected');
  95. });
  96. ws.on('message', function message(data, flags) {
  97. console.log('Roundtrip time: ' + (Date.now() - parseInt(data)) + 'ms', flags);
  98. setTimeout(function timeout() {
  99. ws.send(Date.now().toString(), {mask: true});
  100. }, 500);
  101. });
  102. ```
  103. ### Other examples
  104. For a full example with a browser client communicating with a ws server, see the
  105. examples folder.
  106. Note that the usage together with Express 3.0 is quite different from Express
  107. 2.x. The difference is expressed in the two different serverstats-examples.
  108. Otherwise, see the test cases.
  109. ### Running the tests
  110. ```
  111. make test
  112. ```
  113. ## API Docs
  114. See the doc/ directory for Node.js-like docs for the ws classes.
  115. ## Changelog
  116. We're using the GitHub `releases` for changelog entries.
  117. ## License
  118. (The MIT License)
  119. Copyright (c) 2011 Einar Otto Stangvik &lt;einaros@gmail.com&gt;
  120. Permission is hereby granted, free of charge, to any person obtaining
  121. a copy of this software and associated documentation files (the
  122. 'Software'), to deal in the Software without restriction, including
  123. without limitation the rights to use, copy, modify, merge, publish,
  124. distribute, sublicense, and/or sell copies of the Software, and to
  125. permit persons to whom the Software is furnished to do so, subject to
  126. the following conditions:
  127. The above copyright notice and this permission notice shall be
  128. included in all copies or substantial portions of the Software.
  129. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
  130. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  131. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  132. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  133. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  134. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  135. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  136. [archive]: http://web.archive.org/web/20130314230536/http://hobbycoding.posterous.com/the-fastest-websocket-module-for-nodejs