mirror of
https://github.com/onyx-and-iris/vban-cmd-python.git
synced 2026-03-12 04:59:09 +00:00
resolves the hostname once and use it throughout the package
this is more efficient and fails faster on error. patch bump
This commit is contained in:
parent
c46ca8a8c8
commit
2794b14cf1
@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "vban-cmd"
|
||||
version = "2.10.2"
|
||||
version = "2.10.3"
|
||||
description = "Python interface for the VBAN RT Packet Service (Sendtext)"
|
||||
authors = [{ name = "Onyx and Iris", email = "code@onyxandiris.online" }]
|
||||
license = { text = "MIT" }
|
||||
|
||||
@ -36,6 +36,13 @@ class VbanCmd(abc.ABC):
|
||||
for attr, val in kwargs.items():
|
||||
setattr(self, attr, val)
|
||||
|
||||
try:
|
||||
self._host_ip = socket.gethostbyname(self.host)
|
||||
except socket.gaierror as e:
|
||||
raise VBANCMDConnectionError(
|
||||
f'Unable to resolve hostname {self.host}'
|
||||
) from e
|
||||
|
||||
self._framecounter = 0
|
||||
self._framecounter_lock = threading.Lock()
|
||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
@ -136,14 +143,10 @@ class VbanCmd(abc.ABC):
|
||||
try:
|
||||
self.sock.sendto(
|
||||
VbanPing0Payload.create_packet(self._get_next_framecounter()),
|
||||
(socket.gethostbyname(self.host), self.port),
|
||||
(self._host_ip, self.port),
|
||||
)
|
||||
self.logger.debug(f'PING sent to {self.host}:{self.port}')
|
||||
|
||||
except socket.gaierror as e:
|
||||
raise VBANCMDConnectionError(
|
||||
f'Unable to resolve hostname {self.host}'
|
||||
) from e
|
||||
except Exception as e:
|
||||
raise VBANCMDConnectionError(f'PING failed: {e}') from e
|
||||
|
||||
@ -201,7 +204,7 @@ class VbanCmd(abc.ABC):
|
||||
framecounter=self._get_next_framecounter(),
|
||||
payload=payload,
|
||||
),
|
||||
(socket.gethostbyname(self.host), self.port),
|
||||
(self._host_ip, self.port),
|
||||
)
|
||||
|
||||
def _set_rt(self, cmd: str, val: Union[str, float]):
|
||||
|
||||
@ -33,7 +33,7 @@ class Subscriber(threading.Thread):
|
||||
nbs, self._remote._get_next_framecounter()
|
||||
)
|
||||
self._remote.sock.sendto(
|
||||
sub_packet, (self._remote.host, self._remote.port)
|
||||
sub_packet, (self._remote._host_ip, self._remote.port)
|
||||
)
|
||||
|
||||
self.wait_until_stopped(10)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user