To send a binary JSON message to a TCP server in Ruby, you can use the socket
library and the msgpack
gem.
main.rb284 chars15 lines
In this example, we first use the to_msgpack
method provided by the msgpack
gem to encode a hash as a MessagePack binary string. Next, we open a TCP socket to the server using the TCPSocket.new
method. Then, we send the binary message to the server using the write
method on the socket object. Finally, we close the socket using the close
method.
Note that you'll need to replace 'localhost'
and 8080
with the hostname and port of your TCP server.
gistlibby LogSnag