So, I'm trying to make a mobile multiplayer game, but either the kivy app is not working, either the server's not working, depends on what I put first.
import socket
import time
import kivy
from kivy.app import App
from kivy.uix.label import Label
import pickle
def server():
HEADERSIZE = 10
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((socket.gethostname(), 1243))
s.listen(5)
while True:
pos = 3
clientsocket, address = s.accept()
print(f"Connection from {address} has been established.")
msg = pickle.dumps(pos)
msg = bytes(f"{len(msg):<{HEADERSIZE}}", 'utf-8') + msg
print(msg)
clientsocket.send(msg)
clientsocket.close()
def app():
class MyApp(App):
def build(self):
return Label(text='text')
MyApp().run()
server()
app()
If I run this I can make a connection with another device, but the app's window doesn't shows. I realized that this is because the server has an infinite loop, so I tried the other way around, but I had the problem that the application was also an infinite loop, so I tried using multiprocessing.
import socket
import time
import kivy
from kivy.app import App
from kivy.uix.label import Label
import pickle
from multiprocessing import Process
def server():
HEADERSIZE = 10
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((socket.gethostname(), 1243))
s.listen(5)
while True:
pos = 3
clientsocket, address = s.accept()
print(f"Connection from {address} has been established.")
msg = pickle.dumps(pos)
msg = bytes(f"{len(msg):<{HEADERSIZE}}", 'utf-8') + msg
print(msg)
clientsocket.send(msg)
clientsocket.close()
def app():
class MyApp(App):
def build(self):
return Label(text='text')
MyApp().run()
if __name__=='__main__':
Process(target=app()).start()
Process(target=server()).start()
But the same thing happens. How could I solve this?