Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,67 @@ Socket programming finds applications in various domains, including web developm
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.

<<<<<<< HEAD

=======
## Program:
# Client.py
```
import socket

# Create a socket object
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Connect to the server
client_socket.connect(('localhost', 8000))

# Print the client's socket name
print(f"Client connected from: {client_socket.getsockname()}")

# Receive a message from the server
server_message = client_socket.recv(1024).decode()
print(f"Received from server: {server_message}")

# Send a message to the server
client_socket.send("Acknowledgement received from the client.".encode())

# Close the connection
client_socket.close()
```
# Server.py
```import socket

# Create a socket object
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Bind the socket to the host and port
server_socket.bind(('localhost', 8000))

# Listen for incoming connections (max 1 connection)
server_socket.listen(1)
print("Server is waiting for a connection...")

# Accept the connection
conn, addr = server_socket.accept()
print(f"Connected by {addr}")

# Send a message to the client
conn.send("Hello from the server!".encode())

# Receive a message from the client
data = conn.recv(1024)
print(f"Received from client: {data.decode()}")

# Close the connection
conn.close()
server_socket.close()
```
## Output:

# client:
![alt text](<Screenshot 2026-04-24 141858.png>)
# server:
![alt text](<Screenshot 2026-04-24 141908.png>)

## Result:
Thus the study of Socket Programming Completed Successfully
Binary file added Screenshot 2026-04-24 141858.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshot 2026-04-24 141908.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import socket

# Create a socket object
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Connect to the server
client_socket.connect(('localhost', 8000))

# Print the client's socket name
print(f"Client connected from: {client_socket.getsockname()}")

# Receive a message from the server
server_message = client_socket.recv(1024).decode()
print(f"Received from server: {server_message}")

# Send a message to the server
client_socket.send("Acknowledgement received from the client.".encode())

# Close the connection
client_socket.close()
26 changes: 26 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import socket

# Create a socket object
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Bind the socket to the host and port
server_socket.bind(('localhost', 8000))

# Listen for incoming connections (max 1 connection)
server_socket.listen(1)
print("Server is waiting for a connection...")

# Accept the connection
conn, addr = server_socket.accept()
print(f"Connected by {addr}")

# Send a message to the client
conn.send("Hello from the server!".encode())

# Receive a message from the client
data = conn.recv(1024)
print(f"Received from client: {data.decode()}")

# Close the connection
conn.close()
server_socket.close()