Saturday, May 29, 2021

Chatting application in python

https://www.youtube.com/watch?v=zHUUTGQWjrM

# Server.py

import socket


ser = socket.socket()

ser.bind(("localhost", 999))

ser.listen(3)


while True:

  c, add = ser.accept()

  print(c.recv(1024).decode())

  while True:

    mes = "Server: " + input("Me: ")

    c.send(bytes(mes, "utf-8"))

    print(" " + c.recv(1024).decode())


c.close()



# Client.py

import socket

soc = socket.socket()
soc.connect(("localhost", 999))

while True:
  mess = "Client: " + input("Me: ")
  soc.send(bytes(mess, "utf-8"))
  print(soc.recv(1024).decode())

soc.close()

No comments:

Post a Comment