Bind multi-port at server side for different client connect

102 views
Skip to first unread message

henr...@insightrobotics.com

unread,
Apr 25, 2014, 12:54:13 AM4/25/14
to zer...@googlegroups.com
I want to bind more than one port at server side. Different client connect to server use different port. After I run the first client work fine. But second client can not connect to port 4243. Below is my test code

At server.py
class HelloRPC(object):
    def hello(self, name):
        print   "this is %s  %s" %(name,time.strftime('%Y-%m-%d %H-%m-%S',time.localtime(time.time())))
        return "Hello, %s" %time.strftime('%Y-%m-%d %H-%m-%S',time.localtime(time.time()))
s1 = zerorpc.Server(HelloRPC())
s1.bind("tcp://0.0.0.0:4242")
s1.run()

s2 = zerorpc.Server(HelloRPC())
s2.bind("tcp://0.0.0.0:4243")
s2.run()


At first client.py
c = zerorpc.Client()
c.connect("tcp://127.0.0.1:4242")
while True:
try:
print c.hello('port 4242')
gevent.sleep(5)
except zerorpc.exceptions.LostRemote:
print "Client : Lost connection \n try Reconnect"
c = zerorpc.Client()
c.connect("tcp://127.0.0.1:4242")

At second client.py
c = zerorpc.Client()
c.connect("tcp://127.0.0.1:4243")
while True:
try:
print c.hello('port 4243')
gevent.sleep(5)
except zerorpc.exceptions.LostRemote:
print "Client : Lost connection \n try Reconnect"
c = zerorpc.Client()
c.connect("tcp://127.0.0.1:4243")

François-Xavier Bourlet

unread,
Apr 26, 2014, 3:39:52 PM4/26/14
to zer...@googlegroups.com

.run() is blocking. You are never executing the second bind. Look at how to use gevent to solve your problem.

Alternatively if you want expose the same instance of your server, you can simply bind the same zerorpc service as many time as you want.

--
You received this message because you are subscribed to the Google Groups "zerorpc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zerorpc+u...@googlegroups.com.
To post to this group, send email to zer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/zerorpc/b256e58b-5d09-4b07-8eeb-a2b6d371188f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

henr...@insightrobotics.com

unread,
Apr 28, 2014, 3:18:27 AM4/28/14
to zer...@googlegroups.com
Thanks! I used bind multi-times to solve my problem.
s1.bind("tcp://0.0.0.0:4242")
s1.bind("tcp://0.0.0.0:4243")
s1.run()
Reply all
Reply to author
Forward
0 new messages