FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-osc/pythonosc/udp_client.py at master · nocarryr/python-osc · GitHub
nocarryr
/
python-osc
Public
forked from
attwad/python-osc
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python-osc
/
pythonosc
/
udp_client.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
71 lines (55 loc) · 2.34 KB
Breadcrumbs
python-osc
/
pythonosc
/
udp_client.py
Copy path
File metadata and controls
71 lines (55 loc) · 2.34 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""UDP Clients for sending OSC messages to an OSC server"""
from
collections
import
Iterable
import
socket
from
.
osc_message_builder
import
OscMessageBuilder
from
pythonosc
.
osc_message
import
OscMessage
from
pythonosc
.
osc_bundle
import
OscBundle
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
:
"""Initialize client
As this is UDP it will not actually make any attempt to connect to the
given server at ip:port until the send() method is called.
Args:
address: IP address of server
port: Port of server
allow_broadcast: Allow for broadcast transmissions
"""
for
addr
in
socket
.
getaddrinfo
(
address
,
port
,
type
=
socket
.
SOCK_DGRAM
):
af
,
socktype
,
protocol
,
canonname
,
sa
=
addr
try
:
self
.
_sock
=
socket
.
socket
(
af
,
socktype
)
except
OSError
:
continue
break
self
.
_sock
.
setblocking
(
0
)
if
allow_broadcast
:
self
.
_sock
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_BROADCAST
,
1
)
self
.
_address
=
address
self
.
_port
=
port
def
send
(
self
,
content
:
Union
[
OscMessage
,
OscBundle
])
->
None
:
"""Sends an :class:`OscMessage` or :class:`OscBundle` via UDP
Args:
content: Message or bundle to be sent
"""
self
.
_sock
.
sendto
(
content
.
dgram
, (
self
.
_address
,
self
.
_port
))
class
SimpleUDPClient
(
UDPClient
):
"""Simple OSC client that automatically builds :class:`OscMessage` from arguments"""
def
send_message
(
self
,
address
:
str
,
value
:
Union
[
int
,
float
,
bytes
,
str
,
bool
,
tuple
,
list
])
->
None
:
"""Build :class:`OscMessage` from arguments and send to server
Args:
address: OSC address the message shall go to
value: One or more arguments to be added to the message
"""
builder
=
OscMessageBuilder
(
address
=
address
)
if
value
is
None
:
values
=
[]
elif
not
isinstance
(
value
,
Iterable
)
or
isinstance
(
value
, (
str
,
bytes
)):
values
=
[
value
]
else
:
values
=
value
for
val
in
values
:
builder
.
add_arg
(
val
)
msg
=
builder
.
build
()
self
.
send
(
msg
)
Back
|
FazBrowse Home
|
New Git URL