Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
multicast-study
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
multicast-study
Commits
9c4e83a1
Commit
9c4e83a1
authored
Apr 28, 2022
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parents
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
0 deletions
+70
-0
tmcast.py
tmcast.py
+70
-0
No files found.
tmcast.py
0 → 100755
View file @
9c4e83a1
#!/usr/bin/env python
"""test program to exercise multicast send/receive."""
from
__future__
import
print_function
import
sys
,
struct
,
time
from
socket
import
socket
,
AF_INET
,
SOCK_DGRAM
,
IPPROTO_UDP
,
SOL_SOCKET
,
\
SO_REUSEADDR
,
IPPROTO_IP
,
IP_ADD_MEMBERSHIP
,
IP_MULTICAST_TTL
,
IP_MULTICAST_LOOP
,
\
inet_aton
,
INADDR_ANY
group4
=
'224.1.1.1'
group6
=
'XXX'
port
=
5678
# open_rx returns function to receive from group:port.
def
open_rx
(
group
,
port
):
# XXX autodetect ip4/ip6 based on group addr
sk
=
socket
(
AF_INET
,
SOCK_DGRAM
,
IPPROTO_UDP
)
sk
.
setsockopt
(
SOL_SOCKET
,
SO_REUSEADDR
,
1
)
sk
.
bind
((
group
,
port
))
mreq
=
struct
.
pack
(
"4sl"
,
inet_aton
(
group
),
INADDR_ANY
)
sk
.
setsockopt
(
IPPROTO_IP
,
IP_ADD_MEMBERSHIP
,
mreq
)
def
_
():
# -> data
return
sk
.
recv
(
4096
)
return
_
# open_tx returns function to send to group:port.
def
open_tx
(
group
,
port
,
ttl
=
2
):
sk
=
socket
(
AF_INET
,
SOCK_DGRAM
,
IPPROTO_UDP
)
sk
.
setsockopt
(
IPPROTO_IP
,
IP_MULTICAST_TTL
,
ttl
)
# XXX IP_MULTICAST_LOOP
def
_
(
data
):
return
sk
.
sendto
(
data
,
(
group
,
port
))
return
_
def
txloop
(
pkt
):
tx
=
open_tx
(
group4
,
port
)
i
=
0
while
1
:
i
+=
1
pkt_
=
pkt
+
(
b'%d'
%
i
)
print
(
"tx: %r ..."
%
pkt_
)
tx
(
pkt
+
(
b'%d'
%
i
))
time
.
sleep
(
1
)
def
rxloop
():
rx
=
open_rx
(
group4
,
port
)
while
1
:
pkt
=
rx
()
print
(
"rx: %r"
%
pkt
)
def
main
():
action
=
sys
.
argv
[
1
]
if
action
==
"tx"
:
txloop
(
sys
.
argv
[
2
])
elif
action
==
"rx"
:
rxloop
()
else
:
raise
RuntimeError
(
"Unknown action %r"
%
action
)
if
__name__
==
'__main__'
:
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment