Skip to content

Instantly share code, notes, and snippets.

@Ra1d7
Created September 25, 2019 14:28
Show Gist options
  • Save Ra1d7/4b66c34e99642cf446b46fd831a7c52c to your computer and use it in GitHub Desktop.
Save Ra1d7/4b66c34e99642cf446b46fd831a7c52c to your computer and use it in GitHub Desktop.
The Client for the "chat app" , you run the server first then this (this is only a concept not even close to what work is needed for a real chat app)
import socket
import threading
s= socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((socket.gethostname(),1234))
def send():
global s
while True:
s.send(bytes(
input('MSG: '),'utf-8'))
def recieve():
while True:
global s
msg = s.recv(1024).decode('utf-8')
print(f'Server: \033[32m{msg}\033[0m\n')
t1 = threading.Thread(target=send)
t2 = threading.Thread(target=recieve)
t1.start()
t2.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment