Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SocketClient
- require 'socket'
- def init_conn(host,port)
- @@s = TCPSocket.open host, port
- end
- def send_msg(msg)
- msg.force_encoding("ASCII-8bit")
- len = msg.length
- @@s.puts [len].pack("I>") + msg
- end
- def read_msg()
- alen = @@s.sysread(4)
- newalen = alen.unpack('I>')[0]
- answer = @@s.read(newalen)
- return answer
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement