Last active
March 5, 2020 10:10
-
-
Save carzacc/430d50943715dfbde2bd2082992af9a3 to your computer and use it in GitHub Desktop.
WebSockets post backend
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for(var cl of server.clients) { | |
cl.send(message); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server.on('connection', function connection(client) { | |
client.send(msg); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var WebSocket = require('ws'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var WebSocket = require('ws'); | |
var sqlite = require('sqlite3'); | |
var port = process.env.PORT || 3000; | |
var server = new WebSocket.Server( | |
{ | |
port: port, | |
} | |
) | |
let msg = "Server: Welcome!"; | |
server.on('connection', function connection(client) { | |
client.send(msg); | |
client.on('message', function incoming(message) { | |
msg = message; | |
for(var cl of server.clients) { | |
cl.send(message); | |
} | |
console.log("Received the following message:\n" + message); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let msg = "Server: Welcome!"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var server = new WebSocket.Server( | |
// ... | |
) | |
let msg = "Server: Welcome!"; | |
server.on('connection', function connection(client) { | |
client.send(msg); | |
client.on('message', function incoming(message) { | |
msg = message; | |
for(var cl of server.clients) { | |
cl.send(message); | |
} | |
console.log("Received the following message:\n" + message); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client.on('message', function incoming(message) { | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var port = process.env.PORT || 3000; | |
var server = new WebSocket.Server( | |
{ | |
port: port, | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment