1.Socketprogramming-TCP(3)
1.Socketprogramming-TCP(3)
1. Build a simple client-server system, where you use the client to chat with a dummy
server. The protocol between the client and server is as follows.
Sample output:
Connected to server
Please enter the message to the server: Hello
Server replied: OK
Please enter the message to the server: Hi
Server replied: OK
Please enter the message to the server: Bye
Server replied: Goodbye
Sample output:
Enter the message to be sent: This is Client
Message from Server: This is Client
Do you want to continue: Y
Enter the message to be sent: Connection Established
Message from Server: Connection Established
Do you want to continue: n
4. The Binary Encoding Server: Write a server program for TCP using Python to do
the following: a. Server returns the binary value of the text sent by the client.
Example: for a text string “comnetsii”, the client should receive “01100011 01101111
01101101 01101110 01100101 01110100 01110011 01101001 01101001”
5. Design an client server program using TCP where the server returns the Time to
the client.
Sample output:
$ python client.py
The time got from the server is Sun Dec 19 17:19:31 2021
Server Program
import socket
s = socket.socket()
host = socket.gethostname()
print(host)
port = 12345
s.bind((host, port))
s.listen(5)
while True:
c, addr = s.accept()
print ('Got connection from', addr)
c.send(b'Thank you for connecting')
#c.send(bytes("Socket Programming in Python","utf-8 "))
c.close()
Client Program
import socket
s = socket.socket()
host = socket.gethostname()
port = 12345
print(host)
s.connect((host, port))
print(s.recv(1024).decode())
#print(msg.decode("utf-8"))
s.close()