windows7 python 指定源组播 10049_试图绑定到特定的外部ip :: [Errno 10049]请求的地址在其上下文中无效无法打开socket-(python 2.7)…[通俗易懂]

2022-11-10 13:34:41 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

socket.INADDR_ANY 等于 socket.bind(‘0.0.0.0’)

如果绑定到“0.0.0.0”可以监听所有接口(可用)

Moxa TCP示例:

import socket,time

import thread

#Example client

class _client :

def __init__(self):

self.status = False

def run(self,clientsock,addr):

while 1 :

try:

data = clientsock.recv(BUFF)

if data :

#do something with data

time.sleep(.1)

if self.status == False:

clientsock.close()

break

clientsock.send(next_query)

except Exception,e :

print e

break

client = _client()

ADDR = (“0.0.0.0”, 45500) #so you need port how to decode raw socket data ?

serversock = socket(AF_INET, SOCK_STREAM)

serversock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)

serversock.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1)#gain 50ms tcp delay

serversock.bind(ADDR)

serversock.listen(10)

While True :

clientsock, addr = serversock.accept()

if addr[0] == device_1_IP:

client.status = True

#start device1 thread(moxa is TCP client mode)

thread.start_new_thread(client.run, (clientsock, addr))

#if client.status = False you will be close connection.

But my offer is “use moxa with TCP server mode”

我使用4x5450i 3×5250超过120设备没有任何错误 .

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/188962.html原文链接:https://javaforall.cn

0 人点赞