easy-socket-event
TypeScript icon, indicating that this package has built-in type declarations

2.0.30 • Public • Published

Socket comunication by event

Use events to communicate via socket; Make managing socket communications between your clients and your server easier, more readable (and more typified)

Install package socket-event

Server

Create the socket server

import { SocketServer } from "socket-event/server";

const server = new SocketServer();

Add an event to server

// Register the handler for an example event
server.Event<string>("example", (data: string, sender: net.Socket) => {  
    console.log("\"example\" event handler >>>", data);
});

Liste to the server

server.Listen("localhost", 3001);

Client

Create the socket client and set connected event

import { SocketClient } from "socket-event/client";

const client = new SocketClient();

Create event emitter

const {emit:exampleEmit} = client.EventEmitter<string>("example");

Connect the client

client.Connect("localhost", 3001);

When connected, emit the event

client.connected = () => {
    console.log("Client connected");
    exampleEmit("Example event emit")
};

Readme

Keywords

none

Package Sidebar

Install

npm i easy-socket-event

Weekly Downloads

16

Version

2.0.30

License

ISC

Unpacked Size

51.8 kB

Total Files

34

Last publish

Collaborators

  • steeo