i'm working in a HTML5 multiplayer game, and i need a server to sync player's movement, chat, battles, etc. So I'm looking for ways to use python instead nodejs, because i have I have more familiarity with python. The server is simple:
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.use(express.static(__dirname));
var onlines = 0
var users = []
var chat = ''
io.on('connection', function(socket){
console.log('[!] Um jogador conectou-se.');
onlines += 1
io.emit('updateonlines', [onlines]);
socket.emit('recvmessage', [chat]);
socket.on('disconnect', function(){
console.log('[!] Um jogador desconectou-se.');
onlines -= 1
io.emit('updateonlines', [onlines]);
});
});
[...]
How can i do this?
You might want to have a look at Tornado. It is well-documented and features built-in support for
WebSockets
.If you want to steer clear of the
Tornado
-framework, there are several Python implementations ofSocket.io
.Good luck!