repl.it
@PythinPython/

Server Template 2

Nodejs

No description

fork
loading
Files
  • index.js
  • client
  • Packager files
  • package-lock.json
index.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.use('/', express.static(__dirname + '/client/'));
http.listen(3000, function() {
  console.log('listening on 3000');
});

var tempids = 0;
var totalusers = 0;
io.on('connection', function(socket){
	setInterval(function(){
		io.emit('tw');
	}, 1000);
	socket.on('rui', function(tempidtwo){
		console.log('CM TU' + totalusers);
		totalusers = totalusers + 1;
		io.emit('ruis', [totalusers, tempidtwo]);
	});
	socket.on('msg', function(msgdata){
		if (msgdata[0] == 'pblc') {
			io.emit('pblcR', [msgdata[1], msgdata[2], msgdata[3], msgdata[4]]);
		}else {
			io.emit('msgTo', msgdata)
		}
		console.log('ms');
	});
	socket.on('RNC', function(rncdataA){
		console.log('CT' + rncdataA[0]);
		io.emit('cnnctnTo', [rncdataA[0], rncdataA[1], rncdataA[2]])
	});
	socket.on('ctconfirm', function(conconnectdata){
		console.log('cc');
		io.emit('cnnctnToTwo', conconnectdata);
	});
	socket.on('temp', function(){
		console.log('T' + tempids)
		tempids = tempids + 1;
		//Hopefully this transfers instantly.
		io.emit('greenlight', tempids);
	});
});
?