0% found this document useful (0 votes)
19 views4 pages

CHAT

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, binds it to a port, listens for incoming connections and receives/sends messages. The client code connects to the server socket and also receives/sends 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)
19 views4 pages

CHAT

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, binds it to a port, listens for incoming connections and receives/sends messages. The client code connects to the server socket and also receives/sends 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/ 4

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)

CLIENT 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...")
OUTPUT:
Chat_server:

Client server:

You might also like