1.0.0 • Published 1 year ago

@j-o-r/websocket v1.0.0

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
1 year ago

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.

1.0.0

1 year ago