https://github.com/socketio/socket.io-echo-server
Socket.IO echo server
https://github.com/socketio/socket.io-echo-server
Last synced: 3 months ago
JSON representation
Socket.IO echo server
- Host: GitHub
- URL: https://github.com/socketio/socket.io-echo-server
- Owner: socketio
- License: mit
- Created: 2021-07-27T07:38:44.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-05-15T19:16:42.000Z (over 2 years ago)
- Last Synced: 2025-01-29T13:11:22.402Z (about 1 year ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 5
- Watchers: 2
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Socket.IO echo server
```
$ npm install # install the dependencies
$ npm start # run the server
```
Optional environment variables:
| Variable | Description |
|-----------------|--------------------------------------------------------------------------------|
| `ALLOW_EIO3` | Enable compatibility with Socket.IO v2 clients |
| `ALLOW_CORS` | Allow Cross-Origin Resource Sharing (CORS) from all origins |
| `ALLOW_ADMINUI` | Instrument the server for usage with [the Admin UI](https://admin.socket.io/). |
*Client*
```js
const { io } = require("socket.io-client");
const socket = io("ws://localhost:3000");
// basic emit
socket.emit("ping", 1, "2");
// response listener
socket.onAny((...args) => {
console.log(args); // prints [ 'ping', 1, '2' ]
});
// with an acknowledgement
socket.emit("ack", 3, "4", (...args) => {
console.log(args); // prints [ 'ack', 3, '4' ]
})
```
We purposely did not implement anything related to broadcasting and rooms, as it could easily be abused.