Unable to change port using listen method
- Dominant language
- Python
- Stars
- 114
- Forks
- 26
- PR merge metrics
- No merged PRs in 30d
Description
The listen method does not seem to change the current port. Please see below for a code snippet where I try to change a port with the changePort method. If ```defaut=True```, I get this error:
```RuntimeError: Only one default socket authorized! Please set default=False to other calls to listen()```
And, if ```defaut=False```, I just stop receiving messages on the port. Is this a sort of bug, or is there a right way to change port with OSCpy?
OS: macOS 12.6.6
Python: 3.9.16
OSCpy: 0.6.0
```python
from oscpy.server import OSCThreadServer
SERVER_ADDRESS = "127.0.0.1"
PORT = 3000
OSC_ADDRESS = b"/testAddress"
class OSCTest:
def __init__(self):
self.server = OSCThreadServer()
self.socket = self.server.listen(address=SERVER_ADDRESS,
port=PORT, default=True)
self.server.bind(OSC_ADDRESS, self.handler)
def handler(self, *data):
print(data)
def close(self):
self.server.stop(self.socket)
def changePort(self, newPort):
"""Change the server port to a newPort."""
# Close the current port
self.server.stop(self.socket)
# Listen on the new port
self.socket = self.server.listen(address=SERVER_ADDRESS,
port=newPort, default=False)
# Re-bind the server to handle incoming OSC messages
self.server.bind(OSC_ADDRESS, self.handler)
```
Contributor guide
Research direction
Start by reading the OSCThreadServer.listen(), stop(), and bind() implementations, then run the supplied Python snippet with both default values. Done means determining whether the documented port-change sequence works and, if not, reproducing the failure with a focused test or a clear correction path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100