server.py:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import SocketServer
import json class MyTCPServer(SocketServer.ThreadingTCPServer): allow_reuse_address = True class MyTCPServerHandler(SocketServer.BaseRequestHandler): def handle(self): try: data = json.loads(self.request.recv(1024).strip()) # process the data, i.e. print it: print data # send some 'ok' back self.request.sendall(json.dumps({'return':'ok'})) except Exception, e: print "Exception wile receiving message: ", e server = MyTCPServer(('127.0.0.1', 13370), MyTCPServerHandler) server.serve_forever() |
kivy client.py:
1
2 3 4 5 6 7 8 9 10 11 |
import socket
import json
def send_data(score):
data = {'message':'This is my kivy app', 'score':score} s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('127.0.0.1', 13370)) s.send(json.dumps(data)) result = json.loads(s.recv(1024)) print result s.close() |
# (list) Permissions
android.permissions = INTERNET