Created
April 22, 2013 20:44
-
-
Save pachun/5438382 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Client | |
attr_accessor :socket, :thread, :connection_time | |
def initialize(socket) | |
@socket = socket | |
@connection_time = Time.now | |
end | |
def run | |
@thread = Thread.start do | |
client_handshake | |
end | |
end | |
def kill | |
disconnect | |
Thread.kill @thread | |
end | |
private | |
def client_handshake | |
msg = @socket.gets | |
puts "received:#{msg}" | |
kill if msg != 'CHAT' | |
end | |
def disconnect | |
@socket.close | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment