remove
This commit is contained in:
parent
b24d642f74
commit
348e1cd71f
@ -1,9 +0,0 @@
|
||||
|
||||
|
||||
|
||||
class Register:
|
||||
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
|
@ -1,83 +0,0 @@
|
||||
import socket
|
||||
from PyQt5 import QtCore
|
||||
|
||||
|
||||
def print_new_message(msg):
|
||||
print(msg)
|
||||
|
||||
|
||||
class webServer(QtCore.QObject):
|
||||
|
||||
newMessageSignal = QtCore.pyqtSignal(str)
|
||||
|
||||
def __init__(self, host='localhost', port=12321) -> None:
|
||||
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.socket = None
|
||||
self.server = None
|
||||
self.serverAddr = None
|
||||
|
||||
QtCore.QObject.__init__(self)
|
||||
|
||||
self.newMessageSignal.connect(print_new_message)
|
||||
|
||||
def __enter__(self):
|
||||
|
||||
# create a socket connection
|
||||
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
# bind the socket with host and port
|
||||
self.socket.bind((self.host, self.port))
|
||||
# allow maximum 1 connection to the socket
|
||||
self.socket.listen(1)
|
||||
|
||||
return self
|
||||
|
||||
def __exit__(self, *args):
|
||||
self.socket.close()
|
||||
|
||||
def close(self):
|
||||
self.socket.close()
|
||||
|
||||
def start_listening(self):
|
||||
|
||||
while True:
|
||||
# wait till a client accept connection
|
||||
self.server, self.serverAddr = self.socket.accept()
|
||||
|
||||
msg = self.server.recv(1024)
|
||||
msg = msg.decode()
|
||||
self.newMessageSignal.emit(msg)
|
||||
|
||||
|
||||
class webClient(object):
|
||||
|
||||
def __init__(self, host='localhost', port=12321) -> None:
|
||||
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.socket = None
|
||||
self.client = None
|
||||
|
||||
def __enter__(self):
|
||||
|
||||
# create a socket connection
|
||||
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
||||
# connect it to server and port number on local computer.
|
||||
self.socket.connect((self.host, self.port))
|
||||
self.client = self.socket
|
||||
|
||||
return self
|
||||
|
||||
def __exit__(self, *args):
|
||||
self.socket.close()
|
||||
|
||||
def close(self):
|
||||
self.socket.close()
|
||||
|
||||
def connect(self):
|
||||
self.socket.connect((self.host, self.port))
|
||||
|
||||
def send(self, msg):
|
||||
self.client.send(msg.encode())
|
@ -1,12 +0,0 @@
|
||||
from WebServer import webServer, webClient
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
host = 'localhost'
|
||||
port = 12321
|
||||
|
||||
with webClient(host, port) as client:
|
||||
client.send('hello')
|
||||
client.send('hello')
|
||||
client.send('hello')
|
||||
client.send('hello')
|
@ -1,9 +0,0 @@
|
||||
from WebServer import webServer, webClient
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
host = 'localhost'
|
||||
port = 12321
|
||||
|
||||
with webServer(host, port) as server:
|
||||
server.start_listening()
|
Loading…
Reference in New Issue
Block a user