forked from offchan42/Unity3D-Python-Communication
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
27 lines (22 loc) · 781 Bytes
/
server.py
File metadata and controls
27 lines (22 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#
# Hello World server in Python
# Binds REP socket to tcp://*:5555
# Expects b"Hello" from client, replies with b"World"
#
import time
import zmq
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://*:5555")
while True:
# Wait for next request from client
message = socket.recv()
print("Received request: %s" % message)
# Do some 'work'.
# Try reducing sleep time to 0.01 to see how blazingly fast it communicates
# In the real world usage, you just need to replace time.sleep() with
# whatever work you want python to do, maybe a machine learning task?
time.sleep(1)
# Send reply back to client
# In the real world usage, after you finish your work, send your output here
socket.send(b"World")