This example accompanies the Using WebSockets on Heroku with Node.js tutorial.
node-websockets's Introduction
node-websockets's People
Forkers
raouldke ilhangrn pc1l sdlirjc ferreiros-lab subhashwalunj-cm digideskio drakaven wichopy beninflash hatemlw daveil shanika alexandru981 swad1992 workato kafkaforks antlaw0 julima14 sberkun dzackgarza jentino yeshbourne jaredbledsoe ppeccin fidenz-dilant kdl-albert jwchen119 gspacetech heeheehaha45 proyectbluetootharduinorapsberry f4rr3ll1990 mrinmoyfun nishant147 sarawuthjdp cariaga bejofo multidevicegrace marianabocoi haicanhdieu antwllm masad-frost andrewlphilpott clburlew jpleigh23 bel-uga vitali-borovik jimpick ukik jmjohnmcgovern707 matteomendula anakinyuen abhi4710 meowwoem rizoadev nosmirck leenawat bidva hoodaxd juanandresnyc res63661 adamwarlock001 spidey20 jeancarlos2015 ekudahl huunguyen312 boythx fsw0723 gnoleda miguelitome mross1080 mathias-mike chtnym9 paterlinimatias eerikson tayfnour dwwoelfel marufam pkwete devasteam ryanbekabe theqantas evie-ey 1337funtimez ashishdotme junseobkim olaf-koziara tiagocatita oldmonad inquisitive-brains mishravik jannaiz jviktorartola apotapov yusufdede lichin-lin nahuelvolpe marknagoyo amerharb lteryinode-websockets's Issues
error
i have tried to deploy this on heroku but after a successful deployment when i check to heroku logs, there i got an error
2020-04-16T20:31:39.855061+00:00 app[web.1]: const wss = new Server({ server });
2020-04-16T20:31:39.855062+00:00 app[web.1]: ^
2020-04-16T20:31:39.855067+00:00 app[web.1]:
2020-04-16T20:31:39.855068+00:00 app[web.1]: ReferenceError: server is not defined
2020-04-16T20:31:39.855070+00:00 app[web.1]: at Object. (/app/server.js:13:26)
How to manage esp32 client connect to heroku websocket nodejs server
Dear Sir ,
I have a nodejs server running on a local machine connect to esp32 client that working fine .
Server:
const express = require('express')
const app = express()
const server = require('http').createServer(app);
const WebSocket = require('ws');
const wss = new WebSocket.Server({ server:server });
wss.on('connection', function connection(ws) {
console.log('A new client Connected!');
ws.send('Welcome New Client!');
ws.on('message', function incoming(message) {
console.log('received: %s', message);
server.listen(83, () => console.log(Lisening on port :83
))
client side ๐
#include <WiFi.h>
#include <WiFiClient.h>
//#include <WebSocketsServer.h>
#include <WebSockets.h>
#include <WebSocketsClient.h>
//#include <WebServer.h>
const char* ssid = "X";
const char* password = "X";
IPAddress local_IP(192, 168, 1,65);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255,255,255,0);
IPAddress primaryDNS(8, 8, 8, 8);
// Initialise websockets, web server and servo
//WebSocketsServer webSocket = WebSocketsServer(1337);
WebSocketsClient webSocket;
void setup(void) {
Serial.begin(115200);
// Initialize the output variables as outputs
// Connect to Wi-Fi network with SSID and password
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS)) {
Serial.println("STA Failed to configure");
}
// Connect to Wi-Fi network with SSID and password
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
// while (WiFi.status() != WL_CONNECTED) {
// delay(500);
//digitalWrite(32,HIGH);
//
// //Serial.print(".");
// }
// Print local IP address and start web server
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
webSocket.begin("192.168.1.3", 83, "/");
delay(4000);
webSocket.onEvent(webSocketEvent);
// Configure web server to host HTML files
//server.onNotFound({
// if(!handleFileRead(server.uri()))
// server.send(404, "text/plain", "FileNotFound");
// });
// server.begin();
Serial.println("HTTP server started");
}
void loop() {
// put your main code here, to run repeatedly:
webSocket.loop();
//String message= "hello from client";
//webSocket.broadcastTXT(message);
}
void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
//const int PROG = digitalRead(27);
switch(type) {
// Runs when a user disconnects
case WStype_DISCONNECTED: {
Serial.printf("[WSc] Disconnected!\n");
break;
}
// Runs when a user connects
case WStype_CONNECTED: {
// IPAddress ip = webSocket.remoteIP(num);
Serial.printf("[WSc] Connected to url: %s\n", payload);
webSocket.sendTXT("hello i am Connected");
}
break;
case WStype_TEXT:{
Serial.printf("[WSc] get text: %s\n", payload);
String text = String((char *) &payload[0]);
Serial.println (text);
break;
}
// send data to server
// webSocket.sendBIN(payload, length);
// break;
// case WStype_ERROR:
// case WStype_FRAGMENT_TEXT_START:
// case WStype_FRAGMENT_BIN_START:
// case WStype_FRAGMENT:
// case WStype_FRAGMENT_FIN:
// break;
}
}
How i manage to put this server on heroku cloud to be working?
Connect through an external client
Do I need to change some config in heroku to enable external clients to connect?
I tried to connect using a socket.io client running locally and pointing to wss://herokusite:port but I was never able to connect
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.