Created
February 26, 2018 16:11
-
-
Save anonymous/cb3f116fa46ccd7f4c2bd78807d083b8 to your computer and use it in GitHub Desktop.
main.py server.py
This file contains 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
$ cat main.py | |
from kivy.app import App | |
from kivy.clock import Clock | |
from kivy.lib import osc | |
class Bomberman(App): | |
def build(self): | |
self.osc = osc.listen(ipAddr='', port=osc.init(ipAddr='')) | |
Clock.schedule_interval(self.update_osc, 0) | |
def update_osc(self, *args): | |
osc.readQueue(self.osc) | |
def stop(self): | |
osc.dontListen(self.osc) | |
if __name__ == '__main__': | |
app = Bomberman() | |
app.run() | |
$ cat server.py | |
from kivy.lib import osc | |
import time | |
class Server(object): | |
def __init__(self, **kwargs): | |
osc.init() | |
self.address = kwargs.get('address', '0.0.0.0') | |
self.port = kwargs.get('port', 30000) | |
self.sv_fps = kwargs.get('sv_fps', 60) | |
self.osc = osc.listen(port=30000) | |
osc.bind(self.osc, self.do_update, '/update') | |
def do_update(self, message, source): | |
address, _, action = message | |
if address == '/update': | |
osc.sendMsg( | |
'/ack', | |
(address, action), | |
ipAddr=source[0], | |
port=source[1] | |
) | |
def run(self): | |
while True: | |
start_time = time.clock() | |
osc.readQueue(self.osc) | |
time.sleep(1. / self.sv_fps - start_time + time.clock()) | |
if __name__ == '__main__': | |
server = Server() | |
server.run() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment