Skip to content
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

1st iteration fixes #3

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

1st iteration fixes #3

wants to merge 2 commits into from

Conversation

PavelLinearB
Copy link
Member

@PavelLinearB PavelLinearB commented Feb 19, 2025

workerB

✨ PR Description

Purpose: Implements a basic client-server chat system using socket programming and threading in Python.

Main changes:

  • Created client.py with socket connection and message handling capabilities
  • Implemented server.py with multi-client support using threaded connections
  • Added data encoding/decoding for network communication between clients and server

Generated by LinearB AI and added by gitStream

@PavelLinearB PavelLinearB changed the title strings 1st iteration fixes Feb 19, 2025
Copy link

gitstream-cm bot commented Feb 20, 2025

✨ PR Review

Maintainability - src/server/server.py (Line 34-40)

Details:

Problem: Global connections list is modified without thread safety
Fix: Add mutex lock for connections list access
Why: Prevents race conditions when multiple threads modify the list

+ connection_lock = threading.Lock()

                print("Client " + str(self.address) + " has disconnected")
                self.signal = False
+               with connection_lock:
                    connections.remove(self)
                break

Performance - src/client/client.py & src/server/server.py (Line 10 & 33)

Details:

Problem: Fixed 32-byte buffer size limits message length and wastes bandwidth
Fix: Implement proper message framing with length prefix
Why: Allows variable length messages while maintaining efficiency

- data = socket.recv(32)
+ msg_size = int.from_bytes(socket.recv(4), 'big')
+ data = socket.recv(msg_size)

Potential Bug - src/client/client.py & src/server/server.py (Lines 9-14 & 32-37)

Details:

Problem: Bare except clauses mask important errors
Fix: Catch specific exceptions
Why: Allows proper handling of different error conditions

        try:
            data = socket.recv(32)
            print(str(data.decode('utf-8')))
-       except:
+       except (socket.error, ConnectionResetError) as e:
            print("You have been disconnected from the server")
            signal = False
            break

Generated by LinearB AI and added by gitStream

@linear-b linear-b deleted a comment from gitstream-cm bot Feb 20, 2025
Comment on lines +17 to +19
#Get host and port
host = input("Host: ")
port = int(input("Port: "))
Copy link

Choose a reason for hiding this comment

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

Suggested change
#Get host and port
host = input("Host: ")
port = int(input("Port: "))
#Get host and port
host = input("Host: ");

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

Successfully merging this pull request may close these issues.

2 participants