easy-web-sockets
v1.0.1
Published
```bash npm install easy-web-socket ``` ## Usage ### WebSocketServer ```javascript const ews = require("easy-web-sockets");
Downloads
2
Readme
Installation
npm install easy-web-socket
Usage
WebSocketServer
const ews = require("easy-web-sockets");
const connectedEvent = (connection) => {
console.log("Client connected!");
}
const messageEvent = (message, connection) => {
console.log("Received message from client:", message);
}
const closeEvent = (connection) => {
console.log("Client disconnected!");
}
ews.createServer(3000, connectedEvent, messageEvent, closeEvent);
WebSocketClient
const ews = require("easy-web-sockets");
const errorEvent = (error, connection) => {
console.log("Error:", error)
}
const connectEvent = (connection) => {
console.log("Connected to Server!")
}
const messageEvent = (message, connection) => {
console.log("Received message from Server:", message)
}
ews.createClient("localhost", 3000, errorEvent, connectEvent, messageEvent).then((client) => {
console.log("Connected!")
})