Comments (6)
@epifanio I just ran the code you posted above and it works both on a Raspberry Pi and on Ubuntu 17.04. I am using the same versions of python and zmq as you on the raspberry pi. On Ubuntu I am using python 3.5.3.
from pyzmqnotes.
Hi @MrYsLab, thanks for confirming it does for you.
I tried on an other machine:
laptop runnin osx as client and a remote debian as server. I allowed the firewall on the server and used its real IP and it works just fine.
Now I wander way is not working on my other laptop (same osx version) , I'll check if has something to do with the fireall .. any clue on how to debug "a denied connection" ?
from pyzmqnotes.
I just tried on a different machine here in the office and it works fine! I'll investigate why on my laptop is not working .. Thanks for confirming that it should work. I
from pyzmqnotes.
Oh! seems I found the problem. This I guess has to do with my lack of knowledge about zmq and tcp /socket connection I guess...
To reproduce the problem:
- run the server script
- run the client script
- it should work, then:
- stop the client (ctr+c)
- restart the client -> doesn't work anymore. I need to restart the server and re-run the client to have it working again.
If I stop/restart the server (and leave the client running) I can see it still work fine.
If I stop/restart the client .. it doesn't, the server doesn't receive the pessage anymore.
i need to stop/restart the server to see the new messages coming.
I think the code needs to be changed to handle "N" client to connect/disconnect .. I'll try to go through the documents to find a solution. Thanks for any pointer, a help will be great!
from pyzmqnotes.
I don't have much experience with pairs. I use pub/sub with a forwarder . The Python Banyan library makes extensive use of this pattern.
from pyzmqnotes.
Thanks for your help @MrYsLab.
Of course, it was my fault in implementing the code using the wrong socket type
.
I changed the code to use: zmq.REQ
and zmq.REP
for the client
and server
.
client.py
import zmq
import random
import sys
import time
port = "5556"
if len(sys.argv) > 1:
port = sys.argv[1]
int(port)
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://0.0.0.0:%s" % port)
messaggio='ls -la'
socket.send_string(messaggio)
msg = socket.recv()
print(msg)
server.py
import os
import sys
import subprocess
import zmq
import random
import time
port = "5556"
if len(sys.argv) > 1:
port = sys.argv[1]
int(port)
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://*:%s" % port)
while True:
msg = socket.recv()
print('client meesage: ', msg)
gmsg=msg.split()
try:
proc = subprocess.Popen(gmsg, stdout=subprocess.PIPE)
output = proc.stdout.read()
socket.send_string(output)
except:
pass
time.sleep(0.5)
Now it works as expected.
from pyzmqnotes.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyzmqnotes.