Skip to main content


Python Chat Application (Client & Server)

WATCH THE TUTORIAL FIRST




client.py

#Start the client second
import socket, sys, time

x = socket.socket()
h_name = input(str("Enter hostname:- "))
port = 8000
x.connect((h_name,port))
print("Server Connected...!")
print("Let the Server Type First")

try:
     while 1:
          incoming_message = x.recv(1024)
          incoming_message = incoming_message.decode()
          print()
          print("Server said: ",incoming_message)
          print()
          message = input(str(">>>> "))
          message = message.encode()
          x.send(message)
except:
     print("Server went OFFLINE")
     



server.py

#Start the server first
import socket, sys, time

x = socket.socket()
h_name = socket.gethostname()
print("Your host name is : ", h_name)
port = 8000
x.bind((h_name,port))
x.listen(1)
connection, address = x.accept()
print("Server is ONLINE ! ! !")

try:
     while 1:
          display_mess = input(str(">> "))
          display_mess = display_mess.encode()
          connection.send(display_mess)
          in_message = connection.recv(1024)
          in_message = in_message.decode()
          print()
          print("Client said: ",in_message)
          print()
except:
     print("Client went OFFLINE")
     


🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍

Popular Posts

Python underline string, Python underline text, Underline python print

Python pip - Installing modules from IDLE (Pyton GUI) for python 3.7

Top 40 Python - String Processing in Python | Working with String in Python

Top 11 Essential Python Tips and Tricks

Python Program - When was I born? / Date of Birth / MY BIRTHDAY (using Python3+)





Subscribe to our Channel


Follow us on Facebook Page

Join our python facebook groups



Join us on Telegram