Skip to content

Simple Socket Server #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

bravetiger01
Copy link
Contributor

PR Title

Simple One Client Socket Server

Summary

Creates a simple socket server and client

Description

The changes are as follows:

Checks

in the repository

  • Made no changes that degrades the functioning of the repository
  • Gave each commit a better title (unlike updated README.md)

in the PR

  • Followed the format of the pull_request_template
  • Made the Pull Request in a small level (for the creator's wellfare)
  • Tested the changes you made

Thank You,

Nakul Desai

@DhanushNehru DhanushNehru requested a review from Copilot July 21, 2025 15:21
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a simple socket communication implementation with a server that can handle a single client connection. The implementation demonstrates basic TCP socket programming concepts including server setup, client connection, and echo functionality.

  • Adds a complete socket server and client implementation in Python
  • Includes comprehensive documentation with usage instructions
  • Updates the main repository README to reference the new implementation

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
Single Client Socket Server/server.py Implements TCP socket server that accepts one client and echoes received data
Single Client Socket Server/client.py Implements client that connects to server and sends a test message
Single Client Socket Server/README.md Provides documentation and usage instructions for the socket implementation
README.md Adds entry in the main repository table referencing the new socket server

python server.py
````

This will start the server on `localhost` and listen on a predefined port (usually `localhost:12345` unless configured otherwise).
Copy link
Preview

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation incorrectly states the port as 12345, but the actual code uses port 65432. This should be updated to reflect the correct port number.

Suggested change
This will start the server on `localhost` and listen on a predefined port (usually `localhost:12345` unless configured otherwise).
This will start the server on `localhost` and listen on a predefined port (usually `localhost:65432` unless configured otherwise).

Copilot uses AI. Check for mistakes.


```bash
python server.py
````
Copy link
Preview

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The markdown code block closing has four backticks instead of three, which may cause rendering issues.

Suggested change
````

Copilot uses AI. Check for mistakes.

Comment on lines +10 to +17
conn, addr = s.accept() # Wait for a connection
with conn: # conn is a new socket object usable to send and receive data
print(f"Connected by {addr}") # Accept the connection
while True: # Loop to handle incoming data
data = conn.recv(1024) # Receive data from the connection
if not data:
break
conn.sendall(data) # Echo the received data back to the client
Copy link
Preview

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server only handles one client connection and exits after that client disconnects. Consider wrapping the accept() call in a loop to handle multiple sequential connections.

Suggested change
conn, addr = s.accept() # Wait for a connection
with conn: # conn is a new socket object usable to send and receive data
print(f"Connected by {addr}") # Accept the connection
while True: # Loop to handle incoming data
data = conn.recv(1024) # Receive data from the connection
if not data:
break
conn.sendall(data) # Echo the received data back to the client
while True: # Loop to handle multiple sequential connections
conn, addr = s.accept() # Wait for a connection
with conn: # conn is a new socket object usable to send and receive data
print(f"Connected by {addr}") # Accept the connection
while True: # Loop to handle incoming data
data = conn.recv(1024) # Receive data from the connection
if not data:
break
conn.sendall(data) # Echo the received data back to the client

Copilot uses AI. Check for mistakes.

Comment on lines +14 to +17
data = conn.recv(1024) # Receive data from the connection
if not data:
break
conn.sendall(data) # Echo the received data back to the client
Copy link
Preview

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server doesn't handle potential socket exceptions that could occur during recv() operations. Consider adding error handling for better user experience.

Suggested change
data = conn.recv(1024) # Receive data from the connection
if not data:
break
conn.sendall(data) # Echo the received data back to the client
try:
data = conn.recv(1024) # Receive data from the connection
if not data:
break
conn.sendall(data) # Echo the received data back to the client
except (socket.error, ConnectionResetError) as e:
print(f"Socket error occurred: {e}") # Log the error
break

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simple One client Socket Server
1 participant