Skip to content

Commit f9f0f76

Browse files
author
John Allsup
committed
Modified __init__ to take a family= parameter and pass it through to socket.getaddrinfo
1 parent 483c9fe commit f9f0f76

1 file changed

Lines changed: 2 additions & 12 deletions

File tree

pythonosc/udp_client.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class UDPClient(object):
1919
"""OSC client to send :class:`OscMessage` or :class:`OscBundle` via UDP"""
2020

21-
def __init__(self, address: str, port: int, allow_broadcast: bool = False, force_ipv4 = False, force_ipv6 = False) -> None:
21+
def __init__(self, address: str, port: int, allow_broadcast: bool = False, family: socket.AddressFamily = 0) -> None:
2222
"""Initialize client
2323
2424
As this is UDP it will not actually make any attempt to connect to the
@@ -28,19 +28,9 @@ def __init__(self, address: str, port: int, allow_broadcast: bool = False, force
2828
address: IP address of server
2929
port: Port of server
3030
allow_broadcast: Allow for broadcast transmissions
31-
force_ipv4: require that remote address is IPv4
32-
force_ipv6: require thta remote address is IPv6
31+
family: address family parameter (passed to socket.getaddrinfo)
3332
"""
3433

35-
if force_ipv4 and force_ipv6:
36-
raise ValueError("Can only force one of IPv4 or IPv6")
37-
elif force_ipv4:
38-
family = socket.AF_INET
39-
elif force_ipv6:
40-
family = socket.AF_INET6
41-
else:
42-
family = 0
43-
4434
for addr in socket.getaddrinfo(address, port, type=socket.SOCK_DGRAM, family=family):
4535
af, socktype, protocol, canonname, sa = addr
4636

0 commit comments

Comments
 (0)