Skip to content

Commit

Permalink
Merge pull request #168 from johnallsup/master
Browse files Browse the repository at this point in the history
Add options to UdpClient to force the use of IPv4 when IPv6 is available and vice versa
  • Loading branch information
attwad committed Jan 10, 2023
2 parents 4b40a71 + 9453b0a commit 4bb844f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pythonosc/udp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@

from typing import Union


class UDPClient(object):
"""OSC client to send :class:`OscMessage` or :class:`OscBundle` via UDP"""

def __init__(self, address: str, port: int, allow_broadcast: bool = False) -> None:
def __init__(self, address: str, port: int, allow_broadcast: bool = False, family: socket.AddressFamily = socket.AF_UNSPEC) -> None:
"""Initialize client
As this is UDP it will not actually make any attempt to connect to the
Expand All @@ -29,8 +28,10 @@ def __init__(self, address: str, port: int, allow_broadcast: bool = False) -> No
address: IP address of server
port: Port of server
allow_broadcast: Allow for broadcast transmissions
family: address family parameter (passed to socket.getaddrinfo)
"""
for addr in socket.getaddrinfo(address, port, type=socket.SOCK_DGRAM):

for addr in socket.getaddrinfo(address, port, type=socket.SOCK_DGRAM, family=family):
af, socktype, protocol, canonname, sa = addr

try:
Expand Down

0 comments on commit 4bb844f

Please sign in to comment.