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
nexedi
multicast-study
Commits
209c3adb
Commit
209c3adb
authored
Jun 09, 2022
by
Léo-Paul Géneau
👾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log sent and received messages
parent
bfe46959
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
10 deletions
+19
-10
client6.py
client6.py
+12
-7
server6.py
server6.py
+7
-3
No files found.
client6.py
View file @
209c3adb
import
argparse
import
logging
import
socket
import
struct
import
sys
if
not
hasattr
(
socket
,
'SO_BINDTODEVICE'
):
socket
.
SO_BINDTODEVICE
=
25
hostname
=
socket
.
gethostname
()
logging
.
basicConfig
(
filename
=
hostname
+
'-client6.log'
,
encoding
=
'utf-8'
,
format
=
'%(asctime)s %(message)s'
,
level
=
logging
.
DEBUG
)
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"multicast_group"
,
help
=
"Multicast IPv6 to use for subscription"
)
...
...
@@ -13,19 +16,21 @@ args = parser.parse_args()
server_address
=
(
''
,
10000
)
sock
=
socket
.
socket
(
socket
.
AF_INET6
,
socket
.
SOCK_DGRAM
)
sock
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
sock
.
bind
(
server_address
)
# on all interfaces.
for
ifidx
,
ifname
in
socket
.
socket
.
if_nameindex
():
print
(
"joining %s @ [%d]%s"
%
(
args
.
multicast_group
,
ifidx
,
ifname
))
for
ifidx
,
ifname
in
socket
.
if_nameindex
():
if
ifname
in
(
'lo'
,
'can0'
):
continue
logging
.
info
(
'%s joining %s @ [%d]%s'
,
hostname
,
args
.
multicast_group
,
ifidx
,
ifname
)
bifidx
=
struct
.
pack
(
"@i"
,
ifidx
)
mreq
=
socket
.
inet_pton
(
socket
.
AF_INET6
,
args
.
multicast_group
)
+
\
bifidx
sock
.
setsockopt
(
socket
.
IPPROTO_IPV6
,
socket
.
IPV6_JOIN_GROUP
,
mreq
)
# = IPV6_ADD_MEMBERSHIP
mreq
=
socket
.
inet_pton
(
socket
.
AF_INET6
,
args
.
multicast_group
)
+
bifidx
sock
.
setsockopt
(
socket
.
IPPROTO_IPV6
,
socket
.
IPV6_JOIN_GROUP
,
mreq
)
try
:
while
True
:
data
,
address
=
sock
.
recvfrom
(
10240
)
print
(
data
.
decode
(
"utf-8"
))
logging
.
info
(
'%s received %s'
,
hostname
,
data
.
decode
(
"utf-8"
))
finally
:
sock
.
close
()
server6.py
View file @
209c3adb
import
argparse
import
logging
import
socket
import
struct
import
traceback
hostname
=
socket
.
gethostname
()
logging
.
basicConfig
(
filename
=
hostname
+
'-server6.log'
,
encoding
=
'utf-8'
,
format
=
'%(asctime)s %(message)s'
,
level
=
logging
.
DEBUG
)
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"addr"
,
help
=
"IPv6 address to use for source"
)
parser
.
add_argument
(
"multicast_group"
,
help
=
"Multicast IPv6 address to use for destination"
)
args
=
parser
.
parse_args
()
print
(
args
.
addr
)
print
(
args
.
multicast_group
)
logging
.
info
(
'host %s will send to %s with source address %s'
,
hostname
,
args
.
multicast_group
,
args
.
addr
)
ttl
=
12
sock
=
socket
.
socket
(
socket
.
AF_INET6
,
socket
.
SOCK_DGRAM
)
sock
.
setsockopt
(
socket
.
IPPROTO_IPV6
,
socket
.
IPV6_MULTICAST_HOPS
,
ttl
)
sock
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
sock
.
bind
((
args
.
addr
,
10000
))
try
:
...
...
@@ -21,6 +24,7 @@ try:
input_msg
=
input
(
'msg --> '
)
try
:
sock
.
sendto
(
input_msg
.
encode
(
"utf-8"
),
(
args
.
multicast_group
,
10000
))
logging
.
info
(
'%s sent %s'
,
hostname
,
input_msg
)
except
Exception
:
traceback
.
print_exc
()
continue
...
...
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