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

Experiment 10

The document outlines an experiment on socket programming using TCP, detailing the aim, software requirements, and lab objectives. It provides a theoretical background on socket creation, an algorithm for implementation, and sample code for both server and client. The conclusion emphasizes the successful study and implementation of the client/server model in socket programming.

Uploaded by

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

Experiment 10

The document outlines an experiment on socket programming using TCP, detailing the aim, software requirements, and lab objectives. It provides a theoretical background on socket creation, an algorithm for implementation, and sample code for both server and client. The conclusion emphasizes the successful study and implementation of the client/server model in socket programming.

Uploaded by

ahiresonali2023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Name: Sonali Ahire

[Link]: A-60
Batch: A4
Experiment No.10
Aim: To study and implementation of Socket Programming using TCP.

Software Requirements: Python

Lab Objective: After completion of this experiment, you will able ,


• Implement Socket Programming for clien server architecture.

Theory: Socket creates an endpoint for communication and returns a descriptor.


The domain parameter specifies a common domain this select the protocol
family which will be used for communication.

Algorithm:
1. Create a server socket.
2. Then create a client socket.
3. DataInputStream and DatOutputStream is to abstract different ways to input and
output
4. whether the stream is a file, a web page.
5. Specify the IP address and port number for socket.
6. Close all streams.
7. Close server and client socket.
8. Stop
Program:
Server-
import socket
# Create a socket object
server_socket = [Link](socket.AF_INET, socket.SOCK_STREAM)

# Bind the socket to a host and port


host = '[Link]' # localhost
port = 12345
server_socket.bind((host, port))

# Listen for incoming connections


server_socket.listen(5)
print("Server is listening on", host, port)

while True:
# Accept a new connection
client_socket, addr = server_socket.accept()
print("Connected to:", addr)

# Send a message to the client


client_socket.send(b"Hello from server!")
# Receive a message from the client
message = client_socket.recv(1024).decode()
print("Message from client:", message)

# Close the connection


client_socket.close()

Client-
import socket

# Create a socket object


client_socket = [Link](socket.AF_INET, socket.SOCK_STREAM)

# Connect to the server


host = '[Link]' # localhost
port = 12345
client_socket.connect((host, port))

# Receive a message from the server


message = client_socket.recv(1024).decode()
print("Message from server:", message)

# Send a message to the server


client_socket.send(b"Hello from client!")
# Close the connection
client_socket.close()

Output:

Conclusion: Thus, we studied and implemented the client/server model of socket


programming.

Lab Outcome: Implement the socket programming for client server architecture.

You might also like