Sunday, 25 August 2013

Parsing response from TCPSocket

Parsing response from TCPSocket

I'm attempting to create a ruby script that uses a TCPSocket to
communicate w/ a Minecraft server and return the name, current number of
players, and the maximum number of players. So far I have the following
code
require 'socket'
class MinecraftServer
def self.ping(ip, port = 25565)
server = TCPSocket.new ip, port
server.write "\xfe"
response = []
while line = server.gets
response << line
end
server.close
response = response.join
response
end
end
puts MinecraftServer.ping('xxx.xxx.xxx.xxx')
This gives me something back like &#65533;A Minecraft
Server&#65533;0&#65533;20. This gives me back all of the information but
in a sring when what I would like is a hash. How do I get rid of the odd
characters and put the information into a Hash?

No comments:

Post a Comment