Add preliminary server code

This commit is contained in:
Jaculabilis 2017-09-23 12:36:34 -05:00
parent 8bb5a1b939
commit 5dee4d971c
1 changed files with 32 additions and 0 deletions

32
server.py Normal file
View File

@ -0,0 +1,32 @@
import sys
import zmq
import time
if sys.argv[1] == "send":
PORT = int(sys.argv[2])
DEST = int(sys.argv[3])
sys.stdout.write("Using port {}\n".format(PORT))
sys.stdout.write("Connecting to port {}\n".format(DEST))
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://localhost:{}".format(DEST))
while True:
socket.send(b"Gentlemen.")
message = socket.recv()
sys.stdout.write("Response: {}\n".format(message))
if sys.argv[1] == "recv":
PORT = int(sys.argv[2])
sys.stdout.write("Using port {}\n".format(PORT))
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://*:{}".format(PORT))
while True:
message = socket.recv()
sys.stdout.write("Received message: {}\n".format(message))
time.sleep(1)
socket.send(b"Received")