【发布时间】:2024-01-21 00:13:01
【问题描述】:
我想使用 Rubys TCPSocket-Class 发送原始字节。 有人有一个很好的例子吗?
这个方法我试过了,还是不行:(
require 'socket'
host = '192.168.0.80'
port = 102
s = TCPSocket.new(host, port)
s.write [0x03, 0x00, 0x00, 0x16,
0x11, 0xE0, 0x00, 0x00, 0x00,
0x01, 0x00, 0xC1, 0x02, 0x02,
0x02, 0xC2, 0x02, 0x02, 0x02,
0xC0, 0x01, 0x0A ].pack('C')
puts s.read
s.close
puts "exit"
谢谢:)
【问题讨论】:
-
首先:它的 s.write 而不是 s.send,抱歉……我不知道到底出了什么问题,但似乎 write-method 将我的字节数组转换为一个字符串。
-
我为您编辑了帖子,但以后请自行更正。
标签: ruby tcp network-programming bytearray tcp-ip