Next level requires to convert binary integer to its string representation. All we have to do is read 4 bytes, convert bytes to int then convert it into string. Ruby have unpack method of String class to do required transformation.
Code:
Proof:
Code:
- #!/usr/bin/ruby1.9.1
- require "socket"
- sock = TCPSocket.new('127.0.0.1','2998')
- string = sock.read(4)
- puts string
- i = string.unpack('l')
- puts i
- sock.puts i
- puts sock.gets
- sock.close
Proof:
No comments:
Post a Comment