lightweight-socket
Version:
lightweight socket
63 lines (44 loc) • 1.64 kB
Markdown
Lightweight Socket is a minimal, lightweight, and efficient real-time communication library for Node.js and the browser. It is inspired by Socket.IO but aims to provide a simpler and more streamlined API.
- Real-time bi-directional communication between server and client
- Lightweight and efficient
- Supports both Node.js and browser environments
- Simple and easy-to-use API
You can install Lightweight Socket via npm:
```
npm install lightweight-socket
```
```js
import { Server } from 'lightweight-socket'
const server = new Server({ port: 3000 });
server.on('connection', (client) => {
console.log('A client connected');
client.on('message', (data) => {
console.log('Received message from client:', data);
});
});
```
```js
import { BrowserClient } from 'lightweight-socket';
const client = new BrowserClient('ws://localhost:3000');
client.on('connect', () => {
console.log('Connected to server');
client.emit('message', 'Hello, server!');
});
```
To build the server and browser versions of the library, run:
```
npm run build
```
Contributions are welcome! Please feel free to submit a pull request.
Lightweight Socket is open source software licensed as MIT.
This library is inspired by Socket.IO but is not affiliated with or endorsed by the Socket.IO team. It aims to provide a lightweight alternative for real-time communication in Node.js and browser environments.