Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bind("tcp://*:6001") meaning in python

Tags:

python

zeromq

ipc

I came across a zeromq example code

subscriber = ctx.socket(zmq.XSUB)
subscriber.connect("tcp://localhost:6000")

publisher = ctx.socket(zmq.XPUB)
publisher.bind("tcp://*:6001")

The subscriber (client) is connecting to local host port 6000. But the publisher (the server) is binding to *:6001

What does this mean?

like image 387
liv2hak Avatar asked Mar 03 '26 11:03

liv2hak


2 Answers

It means "all interfaces, port 6001" - a given computer can have more than one network interface (a trivial example would be that the average computer's LAN IP and it's localhost address are two different interfaces. The * means to accept connections from any of them.

like image 193
Amber Avatar answered Mar 04 '26 23:03

Amber


What does it mean to .bind() at port 6000 while .connect() aims at port 6001?

Simply put, these two peers will not meet at this attempt to setup a link to communicate.

While wildcard does work for all <localhost> interfaces, it does not for port#-s.

A .bind() side can open it's receiving policy to accept a connection from any interface "behind" the * wild card, but the port#-s must match.

No exceptions, no excuse.

like image 28
user3666197 Avatar answered Mar 04 '26 23:03

user3666197