Chat Server

--

user1:

import socket
import threading
import pyttsx3

s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.bind(("sender’s ip",3333))
print("\n\n\t\t\t\t\t...START CHATING...")
def sen():
while True:
x = input("you:")
s.sendto(x.encode(),("receiver’s ip",4321))
def rec():
while True:
d = s.recvfrom(1024)
d = d[0].decode()
print("\t\t\t\t\t|win: "+d)
pyttsx3.speak("message from redhat.... ")
g = threading.Thread(target=sen)
h = threading.Thread(target=rec)

g.start()
h.start()

user2:

import socket
import threading
import subprocess

s= socket.socket(socket.AF_INET,socket.SOCK_DGRAM)

ip = “sender’s ip”
port = 4321
s.bind((ip,port))
print(“\t\t\t\t\t…START CHATING… “)

def rec():
while True:
x = s.recvfrom(1024)
x = x[0].decode()
print(“\t\t\t\t|win:”+x)
subprocess.getoutput(“espeak-ng ‘message from windows’”)

def sen():
while True:
msg = input(“you:”)
s.sendto(msg.encode(),(“receiver’s ip”,3333))

g = threading.Thread(target=rec)
h = threading.Thread(target=sen)

g.start()
h.start()

--

--