0% found this document useful (0 votes)
27 views3 pages

CODE

The document contains code for a chat server and client that allows two programs to communicate over a network connection. The server code creates a socket and listens for incoming connections, while the client code connects to the server and allows sending and receiving messages.

Uploaded by

Kanishk C
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views3 pages

CODE

The document contains code for a chat server and client that allows two programs to communicate over a network connection. The server code creates a socket and listens for incoming connections, while the client code connects to the server and allows sending and receiving messages.

Uploaded by

Kanishk C
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

CHAT_SERVER CODE:

import socket
import sys
import time

s=socket.socket()
host=socket.gethostname()
print("server will start on host:",host)
print("")
port=8080
s.bind((host,port))
print("server done binding to the host and port successfully")
print("")
print("server is waiting for incomming connections")
print("")
s.listen(3)
conn,addr=s.accept()
print(addr,"is connected to the server and now online")
while 1:
message=input(str(">>"))
message=message.encode()
conn.send(message)
print("message has been sent...")
incomming_message=conn.recv(1024)
incomming_message=incomming_message.decode()
print("server : ",incomming_message)

CLINET SERVER CODE:

import socket
import sys
import time

s=socket.socket()
host=input(str("enter the hostname of the server:"))
port=8080
s.connect((host,port))
print("connected to server")
while 1:
incomming_message=s.recv(1024)
incomming_message=incomming_message.decode()
print("server : ",incomming_message)
print("")
message=input(str(">>"))
message=message.encode()
s.send(message)
print("message has been sent...")
z

You might also like