Skip to content

Instantly share code, notes, and snippets.

@TvL2386
Created April 1, 2011 05:13
Show Gist options
  • Save TvL2386/897777 to your computer and use it in GitHub Desktop.
Save TvL2386/897777 to your computer and use it in GitHub Desktop.
print_message function from client.rb
def print_message
Thread.new do
loop do
# monitor socket and print data if there is any
result = IO.select([@socket], nil, nil, nil)
if not result.nil?
socket = result[0].first # result[0] is the socket array. In this example there can only be one
data = socket.readpartial 4096
# use print here, because puts automatically appends a newline
print data
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment