Skip to content

Conversation

@pouyahasanamreji
Copy link

Feature: Protocol Selection

This pull request introduces the ability for users to choose the connection protocol (TCP or UDP) when using the ZKLib package. This enhancement provides greater flexibility and control over device communication.

Changes Made:

  1. Updated the ZKLib constructor to accept an optional protocol parameter.
  2. Added a new preferredProtocol property to store the user's protocol preference.
  3. Implemented a new setProtocol method to allow changing the protocol after instantiation.
  4. Modified the createSocket method to respect the preferredProtocol setting.

New Functionality:

Users can now specify their preferred protocol in three ways:

  • 'tcp': Attempts to connect via TCP only
  • 'udp': Attempts to connect via UDP only
  • 'auto': Tries TCP first, then falls back to UDP if TCP fails (default behavior)

Example usage:

// Force TCP connection
const zklib = new ZKLib('192.168.1.201', 4370, 5000, 5200, 'tcp');

// Force UDP connection
const zklib = new ZKLib('192.168.1.201', 4370, 5000, 5200, 'udp');

// Auto mode (default behavior)
const zklib = new ZKLib('192.168.1.201', 4370, 5000, 5200);

// Change protocol after instantiation
zklib.setProtocol('udp');

Testing:

Tested TCP-only, UDP-only, and auto modes with a compatible device.
Verified that the setProtocol method correctly updates the preferred protocol.
Ensured backwards compatibility with existing usage patterns.

Potential Impacts:

This change is backwards compatible and should not affect existing implementations.
Users who explicitly want to use TCP or UDP can now do so without modifying the package internals.

Documentation:

TODO: Update README.md to include information about the new protocol selection feature.

Next Steps:

If approved, we should update the package documentation to reflect this new feature.
Consider adding more comprehensive tests for different protocol scenarios.

I welcome any feedback or suggestions for improvement on this implementation.

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.

1 participant