@j-o-r/websocket
v1.0.0
Published
A simple implementation of an insecure websocket server and client.
Downloads
2
Maintainers
Readme
README.md
WebSocket
A simple WebSocket server and client library for Node.js.
Features
- Runs on localhost for local use
- Supports sending and receiving text messages
- Provides a simple API for creating a WebSocket server and client
Installation
To install the library, use npm:
npm install @j-o-r/websocket
Usage
Creating a WebSocket Server
import { WebSocket } from '@j-o-r/websocket';
const server = new WebSocket.server(8080, (message) => {
console.log('Received message:', message);
server.write('Server response: ' + message);
});
Creating a WebSocket Client
import { WebSocket } from '@j-o-r/websocket';
const client = new WebSocket.client(8080);
client.write('Hello, server!').then((response) => {
console.log('Server response:', response);
});
API
WebSocket.server
port
: The port number for the WebSocket server (default: 8080)outhandler
: A function that handles incoming messages from clients
WebSocket.client
port
: The port number for the WebSocket server
Examples
You can find examples in the scenarios
directory of the repository.
License
This project is licensed under the Apache License 2.0.
License
This project is licensed under the APACHE 2.0 License. See the LICENSE file for details.