OPC-UA:recv(buffersize)函数卡住,没有任何错误/警告消息
有关我的线程相关背景的一些信息:
客户端-服务器连接领域知识:初学者
Python程序员:中高级
我面临的问题:
使用OPCUA协议将客户端连接到服务器(我使用的工具:opcua python-library和VS-code编辑器)。
问题是如何开始的?
- 我尝试使用
node.get_value()
方法(其中node = client.get_node("ns=2;i= 2")
)。那么错误是:“没有类型没有名为‘send_request’的方法”。这让我认为套接字连接没有建立。因此,我尝试首先使用 UAClient.connect_socket() 方法建立套接字连接,这使我找到了问题的根源,即以下代码中的最后一个命令行:
< strong>我的代码:
from opcua import Server
from opcua import Client
from opcua import ua
from ua_client import *
from traceback import print_exc
from opcua import Client
name = "OPC_SIMULATION_SERVER"
addspace = server.register_namespace(name)
node = server.get_objects_node()
Param = node.add_object(addspace, "Parameters")
server = Server()
url = 'opc.tcp://127.0.0.1:4840' # opc server URL (connection works, checked in in command line with "ping")
server.start()
print("Server started at {}".format(url))
client = Client(url) # create client object
ref = client.uaclient # create UAClient object
# establish socket (to my understanding)
ref._uasocket = UASocketClient(ref._timeout, security_policy=ref.security_policy)
host = client.server_url.hostname
port = client.server_url.port
refsock = ref._uasocket
sock = socket.create_connection((host, port), timeout=refsock.timeout)
sock.settimeout(None) # for blocking (doesn’t cause the error)
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
refsock._socket = ua.utils.SocketWrapper(sock)
# ERRATIC LINE: The following command gets stuck without an error/warning message
chunk = refsock._socket.socket.recv(8)
# \==================================================
我应该注意,最初我从节点获取值没有问题。
Some information about my relevant-to-the-thread background:
Client-Server connection domain knowledge: Beginner
Python-programmer: Mid to advanced level
Problem I am facing:
connecting a Client to a Server using the OPCUA protocol (tool I am using: opcua python-library and VS-code editor).
How did the problem start?
- I was attempting to use the
node.get_value()
method (wherenode = client.get_node("ns=2;i=2")
). Then the error is: "None type does not have a method called 'send_request'". This made me think that the socket connection is not established. Therefore, I tried to establish a socket connection first, by using theUAClient.connect_socket()
method, which lead me to the origin of the problem, which is the last command line in the following code:
My code:
from opcua import Server
from opcua import Client
from opcua import ua
from ua_client import *
from traceback import print_exc
from opcua import Client
name = "OPC_SIMULATION_SERVER"
addspace = server.register_namespace(name)
node = server.get_objects_node()
Param = node.add_object(addspace, "Parameters")
server = Server()
url = 'opc.tcp://127.0.0.1:4840' # opc server URL (connection works, checked in in command line with "ping")
server.start()
print("Server started at {}".format(url))
client = Client(url) # create client object
ref = client.uaclient # create UAClient object
# establish socket (to my understanding)
ref._uasocket = UASocketClient(ref._timeout, security_policy=ref.security_policy)
host = client.server_url.hostname
port = client.server_url.port
refsock = ref._uasocket
sock = socket.create_connection((host, port), timeout=refsock.timeout)
sock.settimeout(None) # for blocking (doesn’t cause the error)
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
refsock._socket = ua.utils.SocketWrapper(sock)
# ERRATIC LINE: The following command gets stuck without an error/warning message
chunk = refsock._socket.socket.recv(8)
# \==================================================
I should note that initially I had no problem with getting the value from the node.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论