Error[8]: Undefined offset: 2, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我在 Python中使用ZMQ绑定,我想将客户端绑定到某个端口,然后将该位置发送到其他客户端进行连接. 现在这是基本的绑定代码: subscriber = context.socket(zmq.SUB)...subscriber.bind("tcp://0.0.0.0:12345") 我需要得到的是外部地址,而不是0.0.0.0,假设我的电脑有IP 192.168.1.10,我需要得到“tcp 我在 Python中使用ZMQ绑定,我想将客户端绑定到某个端口,然后将该位置发送到其他客户端进行连接.
现在这是基本的绑定代码:

subscriber = context.socket(zmq.SUB)...subscriber.bind("tcp://0.0.0.0:12345")

我需要得到的是外部地址,而不是0.0.0.0,假设我的电脑有IP 192.168.1.10,我需要得到“tcp://192.168.1.10:12345”并将其发送给其他客户端,因为发送tcp: //0.0.0.0:12345没用.

如何获取ZMQ用于创建套接字的外部IP接口?

在PC上可以有多少个NIC,如果我只是尝试使用普通套接字获取外部IP,它可能无效,因为我不知道NIC ZMQ使用了什么.

解决方法 0.0.0.0(INADDR_ANY)是“任意”地址(不可路由的元地址).这是一种指定“任何IPv4接口”的方法.
这意味着您的所有接口都在侦听端口12345.

要列出所有网络接口,我建议使用像this这样的库

如果你使用的是linux,你可以这样做:

import arrayimport structimport socketimport fcntlSIocgIFCONF = 0x8912  #define SIocgIFCONFBYTES = 4096          # Simply define the byte size# get_iface_List function deFinition # this function will return array of all 'up' interfaces def get_iface_List():    # create the socket object to get the interface List    sck = socket.socket(socket.AF_INET,socket.soCK_DGRAM)    # prepare the struct variable    names = array.array('B','[+++]' * BYTES)    # the trick is to get the List from ioctl    bytelen = struct.unpack('iL',fcntl.ioctl(sck.fileno(),SIocgIFCONF,struct.pack('iL',BYTES,names.buffer_info()[0])))[0]    # convert it to string    namestr = names.tostring()    # return the interfaces as array    return [namestr[i:i+32].split('[+++]',1)[0] for i in range(0,bytelen,32)]# Now,use the function to get the 'up' interfaces arrayifaces = get_iface_List()# well,what to do? print it out maybe... for iface in ifaces: print iface
总结

以上是内存溢出为你收集整理的python – ZeroMQ如何在pyzmq中获取绑定地址全部内容,希望文章能够帮你解决python – ZeroMQ如何在pyzmq中获取绑定地址所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 3, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我在 Python中使用ZMQ绑定,我想将客户端绑定到某个端口,然后将该位置发送到其他客户端进行连接. 现在这是基本的绑定代码: subscriber = context.socket(zmq.SUB)...subscriber.bind("tcp://0.0.0.0:12345") 我需要得到的是外部地址,而不是0.0.0.0,假设我的电脑有IP 192.168.1.10,我需要得到“tcp 我在 Python中使用ZMQ绑定,我想将客户端绑定到某个端口,然后将该位置发送到其他客户端进行连接.
现在这是基本的绑定代码:

subscriber = context.socket(zmq.SUB)...subscriber.bind("tcp://0.0.0.0:12345")

我需要得到的是外部地址,而不是0.0.0.0,假设我的电脑有IP 192.168.1.10,我需要得到“tcp://192.168.1.10:12345”并将其发送给其他客户端,因为发送tcp: //0.0.0.0:12345没用.

如何获取ZMQ用于创建套接字的外部IP接口?

在PC上可以有多少个NIC,如果我只是尝试使用普通套接字获取外部IP,它可能无效,因为我不知道NIC ZMQ使用了什么.

解决方法 0.0.0.0(INADDR_ANY)是“任意”地址(不可路由的元地址).这是一种指定“任何IPv4接口”的方法.
这意味着您的所有接口都在侦听端口12345.

要列出所有网络接口,我建议使用像this这样的库

如果你使用的是linux,你可以这样做:

import arrayimport structimport socketimport fcntlSIocgIFCONF = 0x8912  #define SIocgIFCONFBYTES = 4096          # Simply define the byte size# get_iface_List function deFinition # this function will return array of all 'up' interfaces def get_iface_List():    # create the socket object to get the interface List    sck = socket.socket(socket.AF_INET,socket.soCK_DGRAM)    # prepare the struct variable    names = array.array('B','' * BYTES)    # the trick is to get the List from ioctl    bytelen = struct.unpack('iL',fcntl.ioctl(sck.fileno(),SIocgIFCONF,struct.pack('iL',BYTES,names.buffer_info()[0])))[0]    # convert it to string    namestr = names.tostring()    # return the interfaces as array    return [namestr[i:i+32].split('[+++]',1)[0] for i in range(0,bytelen,32)]# Now,use the function to get the 'up' interfaces arrayifaces = get_iface_List()# well,what to do? print it out maybe... for iface in ifaces: print iface
总结

以上是内存溢出为你收集整理的python – ZeroMQ如何在pyzmq中获取绑定地址全部内容,希望文章能够帮你解决python – ZeroMQ如何在pyzmq中获取绑定地址所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
python – ZeroMQ如何在pyzmq中获取绑定地址_python_内存溢出

python – ZeroMQ如何在pyzmq中获取绑定地址

python – ZeroMQ如何在pyzmq中获取绑定地址,第1张

概述我在 Python中使用ZMQ绑定,我想将客户端绑定到某个端口,然后将该位置发送到其他客户端进行连接. 现在这是基本的绑定代码: subscriber = context.socket(zmq.SUB)...subscriber.bind("tcp://0.0.0.0:12345") 我需要得到的是外部地址,而不是0.0.0.0,假设我的电脑有IP 192.168.1.10,我需要得到“tcp 我在 Python中使用ZMQ绑定,我想将客户端绑定到某个端口,然后将该位置发送到其他客户端进行连接.
现在这是基本的绑定代码:

subscriber = context.socket(zmq.SUB)...subscriber.bind("tcp://0.0.0.0:12345")

我需要得到的是外部地址,而不是0.0.0.0,假设我的电脑有IP 192.168.1.10,我需要得到“tcp://192.168.1.10:12345”并将其发送给其他客户端,因为发送tcp: //0.0.0.0:12345没用.

如何获取ZMQ用于创建套接字的外部IP接口?

在PC上可以有多少个NIC,如果我只是尝试使用普通套接字获取外部IP,它可能无效,因为我不知道NIC ZMQ使用了什么.

解决方法 0.0.0.0(INADDR_ANY)是“任意”地址(不可路由的元地址).这是一种指定“任何IPv4接口”的方法.
这意味着您的所有接口都在侦听端口12345.

要列出所有网络接口,我建议使用像this这样的库

如果你使用的是linux,你可以这样做:

import arrayimport structimport socketimport fcntlSIocgIFCONF = 0x8912  #define SIocgIFCONFBYTES = 4096          # Simply define the byte size# get_iface_List function deFinition # this function will return array of all 'up' interfaces def get_iface_List():    # create the socket object to get the interface List    sck = socket.socket(socket.AF_INET,socket.soCK_DGRAM)    # prepare the struct variable    names = array.array('B','' * BYTES)    # the trick is to get the List from ioctl    bytelen = struct.unpack('iL',fcntl.ioctl(sck.fileno(),SIocgIFCONF,struct.pack('iL',BYTES,names.buffer_info()[0])))[0]    # convert it to string    namestr = names.tostring()    # return the interfaces as array    return [namestr[i:i+32].split('',1)[0] for i in range(0,bytelen,32)]# Now,use the function to get the 'up' interfaces arrayifaces = get_iface_List()# well,what to do? print it out maybe... for iface in ifaces: print iface
总结

以上是内存溢出为你收集整理的python – ZeroMQ如何在pyzmq中获取绑定地址全部内容,希望文章能够帮你解决python – ZeroMQ如何在pyzmq中获取绑定地址所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1196590.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存