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
a8f4c9d3
Commit
a8f4c9d3
authored
Jun 05, 2016
by
Ian Craggs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change python proxy to use Python2
parent
2a8dad13
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
1042 additions
and
2 deletions
+1042
-2
build.xml
build.xml
+2
-2
MQTTV3112.py
test/MQTTV3112.py
+923
-0
mqttsas2.py
test/mqttsas2.py
+117
-0
No files found.
build.xml
View file @
a8f4c9d3
...
...
@@ -82,8 +82,8 @@
</target>
<target
name=
"test"
>
<exec
executable=
"python
3
"
dir=
"test"
spawn=
"true"
>
<arg
value=
"mqttsas.py"
/>
<exec
executable=
"python"
dir=
"test"
spawn=
"true"
>
<arg
value=
"mqttsas
2
.py"
/>
<arg
value=
"${test.hostname}"
/>
</exec>
<if>
...
...
test/MQTTV3112.py
0 → 100644
View file @
a8f4c9d3
This diff is collapsed.
Click to expand it.
test/mqttsas2.py
0 → 100755
View file @
a8f4c9d3
"""
*******************************************************************
Copyright (c) 2013, 2016 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
http://www.eclipse.org/legal/epl-v10.html
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
MQTTV3112
as
MQTTV3
import
socket
,
sys
,
select
,
traceback
,
datetime
,
os
import
SocketServer
as
socketserver
logging
=
True
myWindow
=
None
def
timestamp
():
now
=
datetime
.
datetime
.
now
()
return
now
.
strftime
(
'
%
Y
%
m
%
d
%
H
%
M
%
S'
)
+
str
(
float
(
"."
+
str
(
now
.
microsecond
)))[
1
:]
class
MyHandler
(
socketserver
.
StreamRequestHandler
):
def
handle
(
self
):
if
not
hasattr
(
self
,
"ids"
):
self
.
ids
=
{}
if
not
hasattr
(
self
,
"versions"
):
self
.
versions
=
{}
inbuf
=
True
i
=
o
=
e
=
None
try
:
clients
=
self
.
request
brokers
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
brokers
.
connect
((
brokerhost
,
brokerport
))
while
inbuf
!=
None
:
(
i
,
o
,
e
)
=
select
.
select
([
clients
,
brokers
],
[],
[])
for
s
in
i
:
if
s
==
clients
:
inbuf
=
MQTTV3
.
getPacket
(
clients
)
# get one packet
if
inbuf
==
None
:
break
try
:
packet
=
MQTTV3
.
unpackPacket
(
inbuf
)
if
packet
.
fh
.
MessageType
==
MQTTV3
.
PUBLISH
and
\
packet
.
topicName
==
"MQTTSAS topic"
and
\
packet
.
data
==
b
"TERMINATE"
:
print
(
"Terminating client"
,
self
.
ids
[
id
(
clients
)])
brokers
.
close
()
clients
.
close
()
break
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)
except
:
traceback
.
print_exc
()
brokers
.
send
(
inbuf
)
# pass it on
elif
s
==
brokers
:
inbuf
=
MQTTV3
.
getPacket
(
brokers
)
# get one packet
if
inbuf
==
None
:
break
try
:
print
(
timestamp
(),
"S to C"
,
self
.
ids
[
id
(
clients
)],
repr
(
MQTTV3
.
unpackPacket
(
inbuf
)))
except
:
traceback
.
print_exc
()
clients
.
send
(
inbuf
)
print
(
timestamp
()
+
" client "
+
self
.
ids
[
id
(
clients
)]
+
" connection closing"
)
except
:
print
(
repr
((
i
,
o
,
e
)),
repr
(
inbuf
))
traceback
.
print_exc
()
if
id
(
clients
)
in
self
.
ids
.
keys
():
del
self
.
ids
[
id
(
clients
)]
elif
id
(
clients
)
in
self
.
versions
.
keys
():
del
self
.
versions
[
id
(
clients
)]
class
ThreadingTCPServer
(
socketserver
.
ThreadingMixIn
,
socketserver
.
TCPServer
):
pass
def
run
():
global
brokerhost
,
brokerport
myhost
=
'localhost'
if
len
(
sys
.
argv
)
>
1
:
brokerhost
=
sys
.
argv
[
1
]
else
:
brokerhost
=
'localhost'
if
len
(
sys
.
argv
)
>
2
:
brokerport
=
int
(
sys
.
argv
[
2
])
else
:
brokerport
=
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
.
serve_forever
()
if
__name__
==
"__main__"
:
run
()
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