Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Sockets Workshop Apr 2021
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sabarish
Sockets Workshop Apr 2021
Commits
6c944691
Commit
6c944691
authored
3 years ago
by
Sibidharan
Browse files
Options
Downloads
Patches
Plain Diff
Client code
parent
f73a98a4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
basic.py
+2
-1
2 additions, 1 deletion
basic.py
mqtt_basics.py
+21
-0
21 additions, 0 deletions
mqtt_basics.py
with
23 additions
and
1 deletion
basic.py
+
2
−
1
View file @
6c944691
...
...
@@ -11,13 +11,14 @@ PORT = 3074
def
start_chat_thread
(
conn
,
addr
):
t
=
ChatMsgThread
(
conn
,
addr
)
t
.
start
()
print
(
"
Thread created and offloaded connection with IP {}:{}
"
.
format
(
addr
[
0
],
addr
[
1
]))
class
ChatMsgThread
(
Thread
):
def
__init__
(
self
,
conn
,
addr
):
Thread
.
__init__
(
self
)
self
.
conn
=
conn
self
.
addr
=
addr
print
(
"
IP {} connected
"
.
format
(
addr
[
0
]))
#
print("IP {} connected".format(addr[0]))
def
run
(
self
):
self
.
conn
.
sendall
(
b
"
Send your message, I will be able to see it here.
\n
"
)
...
...
This diff is collapsed.
Click to expand it.
mqtt_basics.py
0 → 100644
+
21
−
0
View file @
6c944691
#!/usr/bin/env python3
import
paho.mqtt.client
as
mqtt
HOST
=
'
broker.hivemq.com
'
PORT
=
1883
TIMEOUT
=
60
def
on_message
(
client
,
userdata
,
message
):
print
(
"
{}: {}
"
.
format
(
message
.
topic
,
str
(
message
.
payload
)))
def
on_connect
(
client
,
userdata
,
flags
,
rc
):
print
(
"
Connected.
"
)
client
.
subscribe
(
'
lahtp
'
)
client
=
mqtt
.
Client
()
client
.
on_message
=
on_message
client
.
on_connect
=
on_connect
client
.
connect
(
HOST
,
PORT
,
TIMEOUT
)
client
.
loop_forever
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment