我正在尝试 UnetStack 手册中指定的 python 代码。在运行tx.py和rx.py 时,当我在终端上打印时成功创建了 UnetSocket 对象,但 send() 函数在接收器处发送 Nonetype 数据。
tx.py ===>>
from unetpy import UnetSocket
s = UnetSocket('localhost',1101)
print(s)
s.send('hellooo',31)
s.close()
Run Code Online (Sandbox Code Playgroud)
rx.py ====== >>>
from unetpy import UnetSocket
s = UnetSocket('localhost',1102)
rx = s.receive()
print('here ',rx)
print('from node : ',bytearray(rx.data).decode())
s.close()
Run Code Online (Sandbox Code Playgroud)
首先,我在模拟器上运行 2-node-network.groovy。然后从终端 rx.py 和下一个 tx.py。
rx.py 回溯错误(最近一次调用):文件“rx.py”,第 6 行,在
print('from node : ',bytearray(rx.data).decode())
AttributeError: 'NoneType' object has no attribute 'data'
Run Code Online (Sandbox Code Playgroud)
O/p at tx.py <unetpy.UnetSocket object at 0x7fe2909d4550>
我是 UnetStack 这个领域的新手,希望得到专家的帮助。
我创建了一个由 4 个节点组成的小型网络。我正在尝试将我的客户端节点(例如节点 B)连接到服务器节点 (A)。我尝试通过shell进行它们之间的通信。我在这方面取得了成功。但是当我通过代理尝试相同时,我遇到了错误。基本上,我的客户端代理保存客户端的套接字代码,我的服务器也是如此。我的目标是在客户端和服务器节点之间进行功能齐全的通信。
我创建了一个服务器代理,客户端代理将这些代理添加到各自的节点堆栈中。在上述代理中,我尝试在相应代理的 .groovy 文件中实现我的服务器套接字代码和客户端套接字代码。服务器代理添加在名为的安装文件中,setup1.groovy
而客户端代理添加在setup2.groovy
. 模拟脚本中相应节点的堆栈部分中提到了这些相应文件的路径。但是,我仍然面临以下错误:
SEVERE: Client/B > Agent cli died: groovy.lang.MissingMethodException: No signature of method: org.arl.unet.api.UnetSocket.connect() is applicable for argument types: (String, Integer) values: [1, 0]
Possible solutions: connect(int, int), collect(), disconnect(), cancel(), collect(groovy.lang.Closure), collect(java.util.Collection, groovy.lang.Closure)
Run Code Online (Sandbox Code Playgroud)
我附上了我的模拟和代理脚本以获得更多见解。
服务器代理文件(server.groovy)
import org.arl.fjage.*
import org.arl.unet.*
import java.lang.String
//import org.arl.fjage.Agent
import org.arl.unet.api.UnetSocket
class server extends UnetAgent {
@Override
void startup() {
def sock = new UnetSocket('localhost',1105)
println('Server is active now!!!!!')
sock.bind(Protocol.DATA)
def …
Run Code Online (Sandbox Code Playgroud)