0% found this document useful (0 votes)
9 views

1.Socketprogramming-TCP(3)

The document outlines various tasks for a Computer Networks Lab at PSG College of Technology, focusing on building client-server applications using sockets in Python. It includes instructions for creating a simple chat system, a string reversal server, an echo server, a binary encoding server, a time-returning server, and sending objects via sockets using pickle. Sample outputs for each task are provided to illustrate expected functionality.

Uploaded by

wimel85164
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

1.Socketprogramming-TCP(3)

The document outlines various tasks for a Computer Networks Lab at PSG College of Technology, focusing on building client-server applications using sockets in Python. It includes instructions for creating a simple chat system, a string reversal server, an echo server, a binary encoding server, a time-returning server, and sending objects via sockets using pickle. Sample outputs for each task are provided to illustrate expected functionality.

Uploaded by

wimel85164
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

PSG COLLEGE OF TECHNOLOGY

DEPARTMENT OF APPLIED MATHEMATICS AND COMPUTATIONAL


SCIENCES

COMPUTER NETWORKS LAB

23XC46 COMPUTER NETWORKS LAB

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.

● The server is first started on a known port.


● The client program is started (server IP and port are provided on the
commandline).
● The client connects to the server, and then asks the user for input. The user
types his message on the terminal (e.g., "Hi", "Bye", "How are you"). The
user's input is sent to the server via the connected socket.
● The server reads the user's input from the client socket. If the user has typed
"Bye" (without the quotes), the server must reply with "Goodbye". For any
other message, the server must reply with "OK".
● The client then reads the reply from the server, and checks that it is accurate
(either "OK" or "Goodbye").
● If the user had typed "Bye", and the server replied with a "Goodbye" correctly,
the client quits. Otherwise, the client asks the user for the next message to
send to the server.

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

2. The problem is to implement a client - server user-level application using sockets .


Server accepts strings from clients and replies with reverse strings. For example,
when client sends “IITHYD”, Server replies with “DYHTII”. Both server and client
have to output both sending & receiving strings on the terminal. The server and client
processes should be run on different machines.
3.Design an echo server .Echo server is a server that echoes back all data it
receives to a client that sent it.

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 server.py &

Got a connection from ('127.0.0.1', 54597)

$ python client.py

The time got from the server is Sun Dec 19 17:19:31 2021

6. Send objects via sockets using pickle


TCP Socket Programming model in Python

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()

You might also like