Skip to content

Instantly share code, notes, and snippets.

@RX14
Last active January 10, 2018 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RX14/e63a511de007f6bf8943159e5d33b26c to your computer and use it in GitHub Desktop.
Save RX14/e63a511de007f6bf8943159e5d33b26c to your computer and use it in GitHub Desktop.
require "socket"
module GameServer
@@users = [] of TCPSocket
def self.handle_client(client)
message = client.gets
client.puts message
end
def self.start(ip : String, port : Int32)
puts "Starting gameserver on IP: #{ip}, port: #{port}"
server = TCPServer.new(ip, port)
while client = server.accept?
spawn handle_client(client)
puts "New client connection!"
users << client
end
end
end
GameServer.start "localhost", 1234
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment