ws not sending message to wss server
See original GitHub issueI updated this drastically becasue I have a new approach but am still getting errors in a particular I am getting this error. This is running nod eone a ec2 instance
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 message listeners added to [WebSocket]. Use emitter.setMaxListeners() to increase limit
This is my app, any time I put a ws call inside of a app.get or app.post I get this error, If I just put it outside those it works. Not sure why
const express = require("express");
const app = express();
const port = 8080;
const WebSocket = require("ws");
const url = "wss://g6q51519w2.execute-api.us-east-1.amazonaws.com/Prod";
const ws = new WebSocket(url);
var EventEmitter = require('events');
const ee = new EventEmitter()
ee.setMaxListeners(0);
ws.on("message", function incoming(data) {
console.log(data);
});
var hmm = {action:"sendmessage", data: "hello world"}
ws.on("open", function open(){
ws.send(JSON.stringify(hmm))
})
app.get("/", (req, res) => {
//var test = { action: "sendmessage", data: "hello world" };
//ws.on("open", function open() {
//ws.send(JSON.stringify(test));
//});
ws.on('error', (error) => {
console.log(error)
});
res.send("Hello World!");
});
app.post("/doorbell", (req, res) => {
var hmm1 = {action:"sendmessage", data: "hello world from post request"}
ws.on("open", function open(){
ws.send(JSON.stringify(hmm1))
})
res.send("heya hey");
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Websocket on("message") not working - Stack Overflow
I am trying to use it to talk client-server and then analyze that message serverside to broadcast a message server-clients. I can't figure...
Read more >WebSocket.send() - Web APIs - MDN Web Docs - Mozilla
send () method enqueues the specified data to be transmitted to the server over the WebSocket connection, increasing the value of bufferedAmount ...
Read more >Using WebSocket requests - Postman Learning Center
IO for a Socket.IO request. Enter the WebSocket server URL. A WebSocket URL begins with ws:// or wss:// . WebSocket URL. Select Connect....
Read more >Part 1 - Send & receive - websockets 10.4 documentation
Part 1 - Send & receive#. In this tutorial, you're going to build a web-based Connect Four game. The web removes the constraint...
Read more >WebSocket - Сучасний підручник з JavaScript
That's because ws:// data is not encrypted, visible for any intermediary. Old proxy servers do not know about WebSocket, they may see “strange”...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can do something like this:
yeah sorry about that I orignally posted here and https://stackoverflow.com/questions/64868510/express-node-js-webssockets-is-recieving-messages-from-websocket-server-but-not but I really appreciate your help. I will close this