Skip to content

Instantly share code, notes, and snippets.

@Ra1d7
Created September 25, 2019 14:29
Show Gist options
  • Save Ra1d7/8582a761336a5d8917ee5ca5242d073f to your computer and use it in GitHub Desktop.
Save Ra1d7/8582a761336a5d8917ee5ca5242d073f to your computer and use it in GitHub Desktop.
This is the server you're supposed to run for the "chat app", then run client.py
import socket
import multiprocessing
import threading
import time
class server:
def setup(self):
print('Setting Up Server..')
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind((socket.gethostname(),1234))
print('[+] Server Setup and Listening [+]')
s.listen(5)
self.client,self.address = s.accept()
print(f'[+] {self.address[0]} Connected! [+]')
def sendmsg(self):
print('Ready to send messages')
while True:
msg = bytes(input('Msg: '),'utf-8')
self.client.send(msg)
def recmsg(self):
print('Ready to recieve messages')
while True:
re_msg = self.client.recv(1024).decode('utf-8')
print(f'{self.address[0]} :\033[32m{re_msg}\033[0m')
serv1 = server()
serv1.setup()
time.sleep(1)
t1 = threading.Thread(target=serv1.sendmsg)
t2 = threading.Thread(target=serv1.recmsg)
t1.start()
t2.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment