Skip to content

eliassn/creamSocket-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

creamSocketClient

CreamSocketClient now has a parser to help you parse different types (json,binary...)

if you are using typescript try adding the following line to your tsconfig file

"moduleResolution": "NodeNext"
  • Example
// client.js

import { CreamSocketClient } from 'creamsocket-client';

const client = new CreamSocketClient({
  host: 'localhost',
  port: 8080,
  path: '/',
});

client.on('open', () => {
  console.log('Connected to the server.');

  // Send a message to the server
  client.sendMessage({ type: 'chat', content: 'Hello, Server!' });
  client.sendNotification({ type: 'alert', message: 'Client has joined chat' });
});

client.on('message', (msg) => {
  console.log('Received message from server:', msg || msg.content);
});

client.on('notification', (notification) => {
  console.log('Received notification from server:', notification|| notification.message);
});

client.on('close', () => {
  console.log('Connection closed by the server.');
});

client.on('error', (err) => {
  console.error('Connection error:', err);
});

// Connect to the server
client.connect();

About

A client light weight framework for webSocket interaction

Resources

License

Stars

Watchers

Forks

Packages

No packages published