Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hidra
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
steinbac
hidra
Commits
4e0b2233
Commit
4e0b2233
authored
9 years ago
by
Manuela Kuhn
Browse files
Options
Downloads
Patches
Plain Diff
First version of a API for the receiverLiveViewer
parent
f79b9c26
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
APIs/receiverLiveViewerAPI.py
+141
-0
141 additions, 0 deletions
APIs/receiverLiveViewerAPI.py
with
141 additions
and
0 deletions
APIs/receiverLiveViewerAPI.py
0 → 100644
+
141
−
0
View file @
4e0b2233
# API to communicate with receiverLiveViewer
import
zmq
import
socket
class
ReceiverQuery
():
context
=
None
signalIp
=
None
signalPort
=
None
dataIp
=
None
hostname
=
None
dataPort
=
None
signalSocket
=
None
dataSocket
=
None
context
=
None
def
__init__
(
self
,
signalPort
,
signalIp
,
dataPort
,
dataIp
=
"
0.0.0.0
"
):
# ZMQ applications always start by creating a context,
# and then using that for creating sockets
# (source: ZeroMQ, Messaging for Many Applications by Pieter Hintjens)
self
.
context
=
zmq
.
Context
()
self
.
signalIp
=
signalIp
self
.
signalPort
=
signalPort
self
.
dataIp
=
dataIp
self
.
hostname
=
socket
.
gethostname
()
self
.
dataPort
=
dataPort
# To send a notification that a Displayer is up and running, a communication socket is needed
self
.
signalSocket
=
self
.
context
.
socket
(
zmq
.
REQ
)
connectionStr
=
"
tcp://
"
+
str
(
self
.
signalIp
)
+
"
:
"
+
str
(
self
.
signalPort
)
print
connectionStr
self
.
signalSocket
.
connect
(
connectionStr
)
print
"
signalSocket is connected to
"
,
connectionStr
# An additional socket is needed to establish the data retriving mechanism
self
.
dataSocket
=
self
.
context
.
socket
(
zmq
.
REQ
)
connectionStr
=
"
tcp://
"
+
str
(
self
.
dataIp
)
+
"
:
"
+
str
(
self
.
dataPort
)
self
.
dataSocket
.
bind
(
connectionStr
)
print
"
dataSocket is bound to
"
,
connectionStr
# Send the signal that the communication infrastructure should be established
print
"
Sending Start Signal to receiver
"
sendMessage
=
"
START_DISPLAYER,
"
+
str
(
self
.
hostname
)
+
"
,
"
+
str
(
self
.
dataPort
)
try
:
self
.
signalSocket
.
send
(
sendMessage
)
# Get the reply.
message
=
self
.
signalSocket
.
recv
()
print
"
Recieved signal:
"
,
message
except
Exception
as
e
:
print
"
Could not communicate with receiver
"
print
"
Error was:
"
,
e
##
#
# Queries the receiver for new files
#
# returns the path of the newest file
#
##
def
communicateWithReceiver
(
self
):
sendMessage
=
"
NEXT_FILE
"
print
"
Asking for next file with message
"
,
sendMessage
try
:
self
.
dataSocket
.
send
(
sendMessage
)
except
Exception
as
e
:
print
"
Could not communicate with receiver
"
print
"
Error was:
"
,
e
return
""
try
:
# Get the reply.
message
=
self
.
dataSocket
.
recv
()
except
Exception
as
e
:
message
=
""
print
"
Could not communicate with receiver
"
print
"
Error was:
"
,
e
return
message
##
#
# Send signal that the displayer is quitting, close ZMQ connections, destoying context
#
##
def
stopZmq
(
self
):
print
"
Sending Start Signal to receiver
"
sendMessage
=
"
STOP_DISPLAYER,
"
+
str
(
self
.
hostname
)
+
"
,
"
+
str
(
self
.
dataPort
)
try
:
self
.
signalSocket
.
send
(
sendMessage
)
# Get the reply.
message
=
self
.
signalSocket
.
recv
()
print
"
Recieved signal:
"
,
message
except
Exception
as
e
:
print
"
Could not communicate with receiver
"
print
"
Error was:
"
,
e
try
:
print
"
closing ZMQ sockets...
"
if
self
.
signalSocket
:
self
.
signalSocket
.
close
(
linger
=
0
)
if
self
.
dataSocket
:
self
.
dataSocket
.
close
(
linger
=
0
)
print
"
closing ZMQ Sockets...done.
"
except
Exception
as
e
:
print
"
closing ZMQ Sockets...failed.
"
print
e
try
:
print
"
closing zmqContext...
"
if
self
.
context
:
self
.
context
.
destroy
()
self
.
context
=
None
"
closing zmqContext...done.
"
except
Exception
as
e
:
print
"
closing zmqContext...failed.
"
print
e
def
__exit__
(
self
):
self
.
stopZmq
()
def
__del__
(
self
):
self
.
stopZmq
()
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