Initial commit.

master
Mikołaj Lubiak 5 months ago
parent 3b47bae433
commit 50075b05b5
  1. 31
      client.py
  2. 32
      server.py

@ -0,0 +1,31 @@
import socket, time, threading
class client():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def __init__(self):
self.s.connect(('127.0.0.1', 12345))
def sMsg(self, msg):
self.s.send(msg.encode())
def rMsg(self):
while True:
d = ''
d = self.s.recv(1024).decode()
print(end=d)
time.sleep(0.1)
def chat(self):
receiving = threading.Thread(target=self.rMsg)
receiving.daemon = True
receiving.start()
while True:
msg = input()
msg = f"\nClient: {msg}\n"
print(msg)
self.sMsg(msg)
if __name__ == '__main__':
Client = client()
Client.chat()

@ -0,0 +1,32 @@
import socket, threading, time
class Server:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def __init__(self):
self.s.bind(('127.0.0.1', 12345))
self.s.listen(5)
self.client, self.addr = self.s.accept()
def rMsg(self):
while True:
d = ''
d = self.client.recv(1024).decode()
print(end=d)
time.sleep(0.1)
def chat(self):
self.receiving = threading.Thread(target=self.rMsg)
self.receiving.daemon = True
self.receiving.start()
while True:
msg = input()
msg = f"\nADMIN: {msg}\n"
print(msg)
self.client.send(msg.encode())
if __name__ == '__main__':
Server_m = Server()
Server_m.chat()
Server_m.receiving.join()
Server_m.s.close()
Loading…
Cancel
Save