simplest way to send raw Byte-arrays using Ruby's TCPSocket-Class

后端 未结 1 750
悲&欢浪女
悲&欢浪女 2020-12-17 06:49

i want to send raw bytes using Rubys TCPSocket-Class. Has someone a good example?

I\'ve tried it in this way, but it does not work :(

require \'soc         


        
相关标签:
1条回答
  • 2020-12-17 07:24

    Try using a "*" after the format directive to eat all the elements in the list:

    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*')
    

    There are lots of neat tricks possible with string#format so it's worth studying the documentation.

    0 讨论(0)
提交回复
热议问题