Skip to content

Commit 4bb844f

Browse files
authored
Merge pull request #168 from johnallsup/master
Add options to UdpClient to force the use of IPv4 when IPv6 is available and vice versa
2 parents 4b40a71 + 9453b0a commit 4bb844f

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

pythonosc/udp_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515

1616
from typing import Union
1717

18-
1918
class UDPClient(object):
2019
"""OSC client to send :class:`OscMessage` or :class:`OscBundle` via UDP"""
2120

22-
def __init__(self, address: str, port: int, allow_broadcast: bool = False) -> None:
21+
def __init__(self, address: str, port: int, allow_broadcast: bool = False, family: socket.AddressFamily = socket.AF_UNSPEC) -> None:
2322
"""Initialize client
2423
2524
As this is UDP it will not actually make any attempt to connect to the
@@ -29,8 +28,10 @@ def __init__(self, address: str, port: int, allow_broadcast: bool = False) -> No
2928
address: IP address of server
3029
port: Port of server
3130
allow_broadcast: Allow for broadcast transmissions
31+
family: address family parameter (passed to socket.getaddrinfo)
3232
"""
33-
for addr in socket.getaddrinfo(address, port, type=socket.SOCK_DGRAM):
33+
34+
for addr in socket.getaddrinfo(address, port, type=socket.SOCK_DGRAM, family=family):
3435
af, socktype, protocol, canonname, sa = addr
3536

3637
try:

0 commit comments

Comments
 (0)