Questions tagged [ws]

ws is a simple to use, blazing fast, and thoroughly tested WebSocket client and server JavaScript implementation.

ws: a Node.js WebSocket library

WebSockets represent a long awaited evolution in client/server technology. They allow a single TCP socket connection to be established between the client and server which allows for bi-directional messages to be distributed with little overhead resulting in a low latency connection.

ws allows to easily implement this protocol on Node applications, both for WebSocket servers and WebSocket clients. This module is not suited for browser apps, which must use the native WebSocket object; the client WebSocket capabilities are designed for Node applications with the role of a client.

Resources

Example

// index.js
const WebSocket = require('ws');

// server code
const wsServer = new WebSocket.Server({port: 8080});
wsServer.on('connection', serverSocket => {
    console.log('server: new connection');
    serverSocket.onopen = evt => console.log('server: open');
    serverSocket.onmessage = evt => console.log('server: message:', evt.data);
    serverSocket.onclose = evt => console.log('server: close');
    setTimeout(() => serverSocket.send('Hello from server'), 1000);
    setTimeout(() => serverSocket.close(), 3000);
});

// client code
const clientSocket = new WebSocket('ws://localhost:8080');
clientSocket.onopen = evt => console.log('client: open');
clientSocket.onmessage = evt => console.log('client: message:', evt.data);
clientSocket.onclose = evt => console.log('client: close');
setTimeout(() => clientSocket.send('Hello from client'), 2000);

Commented standard output of node index.js:

# t=0s
server: new connection
client: open

# t=1s
client: message: Hello from server

# t=2s
server: message: Hello from client

# t=3s
server: close
client: close
341 questions
0
votes
0 answers

EJBs access through WS with mutual SSL authentication

The context of my question is: Configuring security to access EJB through WS -- WFLYEJB0364 Connection rejected I configured Wildfly for SSL secured EJBs with Elytron following the tutorials: How to configure SSL/HTTPS on…
0
votes
0 answers

Is it possible to create a WebSocket object first, then setup handlers and last, connect?

Currently my code looks as follows, because a WebSocket connection is initiated when I invoke the WebSocket constructor. import WebSocket = require('isomorphic-ws'); let socket = new WebSocket(`${host}:${port}`); socket.onerror = (event: { error:…
user1283776
  • 19,640
  • 49
  • 136
  • 276
0
votes
0 answers

Web socket doesn't open on other machines

Web soket connection error I've got a problem with my server. It uses express and express-ws for web sockets. The problem is that this server works fine on the local host. But when i run it with the help of ssh (see localhost.run) and access the…
0
votes
1 answer

Cancel current websocket handling when a new websocket request is made

I am using npm ws module (or actually the wrapper called isomorphic-ws) for websocket connection. NPM Module: isomorphic-ws I use it to receive some array data from a websocket++ server running on the same PC. This data is then processed and…
Aros
  • 199
  • 2
  • 14
-1
votes
0 answers

NodeJS WebSocket not connecting in Production

I have a Node.js server that is running over HTTP on port 8080. I've added a WebSocket server to handle requests requiring real-time data feed. It works fine on my local machine, but when I upload it to my EC2 instance, it throws a connect…
-1
votes
1 answer

UNABLE TO UNSUBSCRIBE HUOBI WEBSOCKET TICKER SUBSCRIPTION

I'm trying to unsubscribe from a HUOBI websocket server but the server is keep sending me the datas. I contacted to support but so far there is no news. Is there anyone who is achieved to unsubscribe? As far as I checked from their API, this is what…
-1
votes
1 answer

Failed to create service Invalid wsdl but it works in the test

Environment: IntelliJ in debug JBoss 7.2 Java 11 jaxws 2.3.0 I have created a client in a JUnit test and work well. The problem comes when I try to execute the method normally. I get the error 'Failed to create service' Caused by:…
Joe
  • 7,749
  • 19
  • 60
  • 110
-1
votes
1 answer

How to call the function from htmlcode

I have JS code, that works as it supposed to. But insetad of calling "islandA.onclick" from the function, I need to call it from the outside - from HTML code. (there are more islands :) $(document).ready(function(){ var islandA =…
Láďa
  • 5
  • 4
-1
votes
1 answer

Websockets handling lost packages

Do Websockets have a mechanism to handle lost data, by default? Oversimplifying here, say I send 3 packages from server (node.js) to client (vue js). Package number 2 is lost. Is there a way to resend it or at least notify the client with an…
codebot
  • 517
  • 8
  • 29
  • 55
-2
votes
1 answer

Simple node.js with ws terminate itself when run. What's wrong?

I just follow the tutorial in https://youtu.be/FduLSXEHLng?t=302, as below const WebSocket = require("ws"); const wss = new WebSocket.Server({ port: 8082 }); wss.on("connection", ws => { console.log("New client connected"); ws.on("close",…
Elye
  • 53,639
  • 54
  • 212
  • 474
-3
votes
1 answer

How to use apollo subscription in production

I have deployed my apollo server in Zeit now 2.0. So got a https endpoint which I can use in apollo client. But my apollo-server has subscription and to use it in apollo client which requires a ws endpoint. So any suggestion how do I get the ws…
Sujoy Saha
  • 220
  • 1
  • 13
1 2 3
22
23