From 9a5c2e81170e9ddb8c43d6f93cf65836be5bf317 Mon Sep 17 00:00:00 2001 From: AJAI Date: Wed, 29 Apr 2026 10:52:18 +0530 Subject: [PATCH] Update README.md --- README.md | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4adef36e..31e5d763 100644 --- a/README.md +++ b/README.md @@ -51,8 +51,65 @@ Socket programming finds applications in various domains, including web developm 2. Chat Application: Instant messaging and chat applications use sockets to enable real-time communication between users. 3. File Transfer Protocol: Protocols like FTP (File Transfer Protocol) utilize socket programming for transferring files between a client and a server. 4. Networked Games: Online multiplayer games rely on socket programming to facilitate communication between game clients and servers. -5. RPC mechanisms: which allow processes to execute code on a remote server, often use socket programming for communication. +5. RPC mechanisms: which allow processes to execute code on a remote server, often use socket programming for communication +##server: +import socket +# Create socket +server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + +# Bind socket to IP and port +host = '127.0.0.1' +port = 12345 +server_socket.bind((host, port)) + +# Listen for connections +server_socket.listen(1) +print("Server is waiting for connection...") + +# Accept client connection +conn, addr = server_socket.accept() +print("Connected to:", addr) + +# Receive data from client +data = conn.recv(1024).decode() +print("Client says:", data) + +# Send response to client +message = "Hello Client, message received!" +conn.send(message.encode()) + +# Close connection +conn.close() +server_socket.close() +## Output: +exp-1 (1) + + +## client: +import socket + +# Create socket +client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + +# Connect to server +host = '127.0.0.1' +port = 12345 +client_socket.connect((host, port)) + +# Send message to server +message = "Hello Server!" +client_socket.send(message.encode()) + +# Receive response from server +data = client_socket.recv(1024).decode() +print("Server says:", data) + +# Close socket +client_socket.close() +## output: + +exp-1 (2) ## Result: Thus the study of Socket Programming Completed Successfully