我想发送一组数据包,如下所示:
\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B
Run Code Online (Sandbox Code Playgroud)
到我的电脑192.168.123.45上的端口102.
这是昨天写的Ruby中的一个小程序,它完成了这项工作.现在我想在C中做这个,最终为了拥有一个Windows可执行文件,但我被卡住了.
有人知道如何用C做这个Ruby程序吗?谢谢.
require 'socket'
myport = 102
myhost = '192.168.123.45'
mysock = TCPSocket.new(myhost, myport)
mysock.write [0x01, 0x02, 0x03, 0x04,
0x05, 0x06, 0x07, 0x08,
0x09, 0x0A, 0x0B].pack('C*')
puts mysock.read
mysock.close
puts "End of socket"
Run Code Online (Sandbox Code Playgroud)