forked from orangeable/javascript-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
30 lines (21 loc) · 628 Bytes
/
app.js
File metadata and controls
30 lines (21 loc) · 628 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// include dependencies:
var websocket = require("websocket").server;
var http = require("http");
// local variables:
var username = "You";
var port = 9600;
// create server, and have listen on port 9600:
var server = http.createServer();
server.listen(port, function() {
console.log("Server listening on port " + port);
});
var ws_server = new websocket({
httpServer: server
});
// on server request, send message:
ws_server.on("request", function(req) {
var connection = req.accept(null, req.origin);
connection.on("message", function(message) {
connection.send(message.utf8Data);
});
});