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
4528f190
Commit
4528f190
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
17 additions
and
10 deletions
+17
-10
client6.py
client6.py
+11
-7
server6.py
server6.py
+6
-3
No files found.
client6.py
View file @
4528f190
import
argparse
import
argparse
import
logging
import
socket
import
socket
import
struct
import
struct
import
sys
if
not
hasattr
(
socket
,
'SO_BINDTODEVICE'
):
if
not
hasattr
(
socket
,
'SO_BINDTODEVICE'
):
socket
.
SO_BINDTODEVICE
=
25
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
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"multicast_group"
,
help
=
"Multicast IPv6 to use for subscription"
)
parser
.
add_argument
(
"multicast_group"
,
help
=
"Multicast IPv6 to use for subscription"
)
...
@@ -16,16 +19,17 @@ sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
...
@@ -16,16 +19,17 @@ sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
sock
.
bind
(
server_address
)
sock
.
bind
(
server_address
)
# on all interfaces.
# on all interfaces.
for
ifidx
,
ifname
in
socket
.
socket
.
if_nameindex
():
for
ifidx
,
ifname
in
socket
.
if_nameindex
():
print
(
"joining %s @ [%d]%s"
%
(
args
.
multicast_group
,
ifidx
,
ifname
))
if
ifname
in
(
'lo'
,
'can0'
):
continue
logging
.
info
(
'%s joining %s @ [%d]%s'
,
hostname
,
args
.
multicast_group
,
ifidx
,
ifname
)
bifidx
=
struct
.
pack
(
"@i"
,
ifidx
)
bifidx
=
struct
.
pack
(
"@i"
,
ifidx
)
mreq
=
socket
.
inet_pton
(
socket
.
AF_INET6
,
args
.
multicast_group
)
+
\
mreq
=
socket
.
inet_pton
(
socket
.
AF_INET6
,
args
.
multicast_group
)
+
bifidx
bifidx
sock
.
setsockopt
(
socket
.
IPPROTO_IPV6
,
socket
.
IPV6_JOIN_GROUP
,
mreq
)
sock
.
setsockopt
(
socket
.
IPPROTO_IPV6
,
socket
.
IPV6_JOIN_GROUP
,
mreq
)
# = IPV6_ADD_MEMBERSHIP
try
:
try
:
while
True
:
while
True
:
data
,
address
=
sock
.
recvfrom
(
10240
)
data
,
address
=
sock
.
recvfrom
(
10240
)
print
(
data
.
decode
(
"utf-8"
))
logging
.
info
(
'%s received %s'
,
hostname
,
data
.
decode
(
"utf-8"
))
finally
:
finally
:
sock
.
close
()
sock
.
close
()
server6.py
View file @
4528f190
import
argparse
import
argparse
import
logging
import
socket
import
socket
import
struct
import
traceback
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
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"addr"
,
help
=
"IPv6 address to use for source"
)
parser
.
add_argument
(
"addr"
,
help
=
"IPv6 address to use for source"
)
parser
.
add_argument
(
"multicast_group"
,
help
=
"Multicast IPv6 address to use for destination"
)
parser
.
add_argument
(
"multicast_group"
,
help
=
"Multicast IPv6 address to use for destination"
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
print
(
args
.
addr
)
logging
.
info
(
'host %s will send to %s with source address %s'
,
hostname
,
args
.
multicast_group
,
args
.
addr
)
print
(
args
.
multicast_group
)
ttl
=
12
ttl
=
12
sock
=
socket
.
socket
(
socket
.
AF_INET6
,
socket
.
SOCK_DGRAM
)
sock
=
socket
.
socket
(
socket
.
AF_INET6
,
socket
.
SOCK_DGRAM
)
...
@@ -21,6 +23,7 @@ try:
...
@@ -21,6 +23,7 @@ try:
input_msg
=
input
(
'msg --> '
)
input_msg
=
input
(
'msg --> '
)
try
:
try
:
sock
.
sendto
(
input_msg
.
encode
(
"utf-8"
),
(
args
.
multicast_group
,
10000
))
sock
.
sendto
(
input_msg
.
encode
(
"utf-8"
),
(
args
.
multicast_group
,
10000
))
logging
.
info
(
'%s sent %s'
,
hostname
,
input_msg
)
except
Exception
:
except
Exception
:
traceback
.
print_exc
()
traceback
.
print_exc
()
continue
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