From 74e60772ed23a983940bc6d97fca57341b25dc5f Mon Sep 17 00:00:00 2001 From: Billy Brown Date: Sat, 2 Dec 2017 15:16:37 +0000 Subject: Importing client in main file --- client/Client.py | 64 ------------------------------------------------------ client/client.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ client/longpong.py | 1 + 3 files changed, 65 insertions(+), 64 deletions(-) delete mode 100644 client/Client.py create mode 100644 client/client.py diff --git a/client/Client.py b/client/Client.py deleted file mode 100644 index bddb56b..0000000 --- a/client/Client.py +++ /dev/null @@ -1,64 +0,0 @@ -import socket -import sys -import json - -class Client: - def __init__(self,ip,port,n): - self.started = False - self.stopped = False - self.msgs =[] - self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.sock.connect((ip,port)) - self.n = n - self.client_sock.setblocking(False) - - def listen(self): - try: - msg = client_sock.recv(4096) - jsonMSG = json.loads(msg) - print(jsonMSG) - if 'command' in data: - val = jsonMSG['command'] - if val == 'start': - self.started = True - self.startupMessage = jsonMSG - elif val =='stop': - self.stopped = True - self.stoppedMessage = jsonMSG - else: - msgs.append(jsonMSG) - else: - print("It really shouldn't be here") - - except socket.error, e: - - def get_messages(self): - ret = self.msgs[:] - self.msgs = [] - - def send_init(self,screen): - inp = {} - inp['nValue'] = self.n; - inp['screenSize'] = str(screen) - self.client_sock.send(str(json.dumps(inp))) - - def send_start(self): - msg ={'command':'start'} - jsonVal = json.dumps(msg) - self.client_sock.send(str(jsonVal)) - - def send_stop(self): - msg ={'command':'stop'} - jsonVal = json.dumps(msg) - self.client_sock.send(str(jsonVal)) - - def send_ballchange(self,message): - msg['command'] = "bchange" - jsonVal = json.dumps(msg) - self.client_sock.send(str(jsonVal)) - - def has_started(self): - return self.started - - def has_stopped(self): - return self.stopped diff --git a/client/client.py b/client/client.py new file mode 100644 index 0000000..bddb56b --- /dev/null +++ b/client/client.py @@ -0,0 +1,64 @@ +import socket +import sys +import json + +class Client: + def __init__(self,ip,port,n): + self.started = False + self.stopped = False + self.msgs =[] + self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.sock.connect((ip,port)) + self.n = n + self.client_sock.setblocking(False) + + def listen(self): + try: + msg = client_sock.recv(4096) + jsonMSG = json.loads(msg) + print(jsonMSG) + if 'command' in data: + val = jsonMSG['command'] + if val == 'start': + self.started = True + self.startupMessage = jsonMSG + elif val =='stop': + self.stopped = True + self.stoppedMessage = jsonMSG + else: + msgs.append(jsonMSG) + else: + print("It really shouldn't be here") + + except socket.error, e: + + def get_messages(self): + ret = self.msgs[:] + self.msgs = [] + + def send_init(self,screen): + inp = {} + inp['nValue'] = self.n; + inp['screenSize'] = str(screen) + self.client_sock.send(str(json.dumps(inp))) + + def send_start(self): + msg ={'command':'start'} + jsonVal = json.dumps(msg) + self.client_sock.send(str(jsonVal)) + + def send_stop(self): + msg ={'command':'stop'} + jsonVal = json.dumps(msg) + self.client_sock.send(str(jsonVal)) + + def send_ballchange(self,message): + msg['command'] = "bchange" + jsonVal = json.dumps(msg) + self.client_sock.send(str(jsonVal)) + + def has_started(self): + return self.started + + def has_stopped(self): + return self.stopped diff --git a/client/longpong.py b/client/longpong.py index f7531c8..7300af1 100644 --- a/client/longpong.py +++ b/client/longpong.py @@ -1,6 +1,7 @@ import sdl2.ext import sys +import client import events import game import render -- cgit v1.2.1