Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
paho.mqtt.c
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
eclipse
paho.mqtt.c
Commits
9c4a917f
Commit
9c4a917f
authored
Mar 21, 2018
by
Ian Craggs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow test proxy to work with either Python 2 or 3
parent
5ed757d8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
22 deletions
+39
-22
mqttsas.py
test/mqttsas.py
+38
-21
travis-build.sh
travis-build.sh
+1
-1
No files found.
test/mqttsas.py
View file @
9c4a917f
"""
*******************************************************************
Copyright (c) 2013, 201
6
IBM Corp.
Copyright (c) 2013, 201
8
IBM Corp.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
and Eclipse Distribution License v1.0 which accompany this distribution.
The Eclipse Public License is available at
and Eclipse Distribution License v1.0 which accompany this distribution.
The Eclipse Public License is available at
http://www.eclipse.org/legal/epl-v10.html
and the Eclipse Distribution License is available at
and the Eclipse Distribution License is available at
http://www.eclipse.org/org/documents/edl-v10.php.
Contributors:
Ian Craggs - initial implementation and/or documentation
*******************************************************************
"""
from
__future__
import
print_function
# Trace MQTT traffic
import
MQTTV311
as
MQTTV3
import
socket
,
sys
,
select
,
traceback
,
datetime
,
os
,
socketserver
import
socket
,
sys
,
select
,
traceback
,
datetime
,
os
try
:
import
socketserver
import
MQTTV311
as
MQTTV3
# Trace MQTT traffic - Python 3 version
except
:
import
SocketServer
as
socketserver
import
MQTTV3112
as
MQTTV3
# Trace MQTT traffic - Python 2 version
logging
=
True
myWindow
=
None
...
...
@@ -29,6 +33,7 @@ def timestamp():
now
=
datetime
.
datetime
.
now
()
return
now
.
strftime
(
'
%
Y
%
m
%
d
%
H
%
M
%
S'
)
+
str
(
float
(
"."
+
str
(
now
.
microsecond
)))[
1
:]
suspended
=
[]
class
MyHandler
(
socketserver
.
StreamRequestHandler
):
...
...
@@ -43,10 +48,13 @@ class MyHandler(socketserver.StreamRequestHandler):
clients
=
self
.
request
brokers
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
brokers
.
connect
((
brokerhost
,
brokerport
))
while
inbuf
!=
None
:
terminated
=
False
while
inbuf
!=
None
and
not
terminated
:
(
i
,
o
,
e
)
=
select
.
select
([
clients
,
brokers
],
[],
[])
for
s
in
i
:
if
s
==
clients
:
if
s
in
suspended
:
print
(
"suspended"
)
if
s
==
clients
and
s
not
in
suspended
:
inbuf
=
MQTTV3
.
getPacket
(
clients
)
# get one packet
if
inbuf
==
None
:
break
...
...
@@ -58,13 +66,19 @@ class MyHandler(socketserver.StreamRequestHandler):
print
(
"Terminating client"
,
self
.
ids
[
id
(
clients
)])
brokers
.
close
()
clients
.
close
()
terminated
=
True
break
elif
packet
.
fh
.
MessageType
==
MQTTV3
.
PUBLISH
and
\
packet
.
topicName
==
"MQTTSAS topic"
and
\
packet
.
data
==
b
"TERMINATE_SERVER"
:
print
(
"Suspending client "
,
self
.
ids
[
id
(
clients
)])
suspended
.
append
(
clients
)
elif
packet
.
fh
.
MessageType
==
MQTTV3
.
CONNECT
:
self
.
ids
[
id
(
clients
)]
=
packet
.
ClientIdentifier
self
.
versions
[
id
(
clients
)]
=
3
print
(
timestamp
()
,
"C to S"
,
self
.
ids
[
id
(
clients
)],
repr
(
packet
))
print
([
hex
(
b
)
for
b
in
inbuf
])
print
(
inbuf
)
#
print([hex(b) for b in inbuf])
#
print(inbuf)
except
:
traceback
.
print_exc
()
brokers
.
send
(
inbuf
)
# pass it on
...
...
@@ -91,24 +105,27 @@ class ThreadingTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
def
run
():
global
brokerhost
,
brokerport
myhost
=
'
localhost
'
myhost
=
'
127.0.0.1
'
if
len
(
sys
.
argv
)
>
1
:
brokerhost
=
sys
.
argv
[
1
]
else
:
brokerhost
=
'
localhost
'
brokerhost
=
'
127.0.0.1
'
if
len
(
sys
.
argv
)
>
2
:
brokerport
=
int
(
sys
.
argv
[
2
])
else
:
brokerport
=
1883
if
brokerhost
==
myhost
:
myport
=
brokerport
+
1
if
len
(
sys
.
argv
)
>
3
:
myport
=
int
(
sys
.
argv
[
3
])
else
:
myport
=
1883
if
brokerhost
==
myhost
:
myport
=
brokerport
+
1
else
:
myport
=
1883
print
(
"Listening on port"
,
str
(
myport
)
+
", broker on port"
,
brokerport
)
s
=
ThreadingTCPServer
((
""
,
myport
),
MyHandler
)
s
=
ThreadingTCPServer
((
"
127.0.0.1
"
,
myport
),
MyHandler
)
s
.
serve_forever
()
if
__name__
==
"__main__"
:
...
...
travis-build.sh
View file @
9c4a917f
...
...
@@ -8,7 +8,7 @@ cd build.paho
echo
"travis build dir
$TRAVIS_BUILD_DIR
pwd
$PWD
"
cmake
-DPAHO_WITH_SSL
=
TRUE
-DPAHO_BUILD_DOCUMENTATION
=
FALSE
-DPAHO_BUILD_SAMPLES
=
TRUE ..
make
python ../test/mqttsas
2
.py &
python ../test/mqttsas.py &
ctest
-VV
--timeout
600
kill
%1
#killall mosquitto
...
...
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