[go: up one dir, main page]

0% found this document useful (0 votes)
2 views2 pages

CN Exp2

Socket programming enables communication between systems over a network, essential for applications like web servers and chat applications. The Client-Server model involves a server that listens for requests and a client that sends requests. In Python, the socket module is used to implement this model, with specific server and client code to handle connections and data exchange.

Uploaded by

rspihu731840
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)
2 views2 pages

CN Exp2

Socket programming enables communication between systems over a network, essential for applications like web servers and chat applications. The Client-Server model involves a server that listens for requests and a client that sends requests. In Python, the socket module is used to implement this model, with specific server and client code to handle connections and data exchange.

Uploaded by

rspihu731840
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
You are on page 1/ 2

Socket Programming and Client-Server Model

Socket programming is a way to enable communication between two systems over a network. It is a
crucial part of network communication in many applications, including web servers, chat
applications, and file transfer protocols.

The Client-Server model is one of the most common models in socket programming, where one
machine (the server) listens for requests, and another machine (the client) sends requests to the
server.

Python Socket Programming

In Python, we use the socket module for creating sockets.

Client-Server Architecture:

• Server: Listens on a specific port for incoming connections.

• Client: Connects to the server at a specific IP and port, sends requests, and receives
responses.

Server Code in Python (TCP Server):


Client Code in Python (TCP Client):

Explanation:

1. Server Code:

o The server creates a socket using socket.socket().

o It binds the socket to an IP (127.0.0.1) and port (8080).

o The server listens for incoming connections using listen().

o Once a connection is established, the server receives data, processes it (in this case,
converting to uppercase), and sends the response back to the client.

2. Client Code:

o The client creates a socket and connects to the server at the specified IP and port
using connect().

o It sends a message to the server and waits for a response. If the message is "bye",
the connection is closed.

You might also like