You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
855 B
JavaScript

2 years ago
var http = require('http');
var fs = require('fs');
var express = require('express');
var app = express();
var path = require('path');
1 year ago
2 years ago
var server = http.createServer(app);
var port = 8000;
1 year ago
var io = require('socket.io')(server);
1 year ago
io.on('connection', function(socket) {
console.log('Node.js is listening!!');
1 year ago
1 year ago
socket.on("hello", (arg, callback) => {
1 year ago
console.log("hellohelo"); // "world"
io.emit('blink');
1 year ago
});
1 year ago
1 year ago
socket.on('chat message', (msg) => {
console.log('[user][' + socket.id + '][' + msg + ']');
});
2 years ago
1 year ago
socket.on('userposition', (msg) => {
console.log('[user][' + socket.id + '][position: ' + msg[0] + ',' + msg[1] + ']');
socket.to('expo').emit(socket.id, msg);
});
2 years ago
});
1 year ago
server.listen(port, () => {
console.log("Server is listening at port %d", port);
});
2 years ago
1 year ago
app.use(express.static(path.join(__dirname, "public")));