Last active
January 10, 2018 00:10
-
-
Save RX14/e63a511de007f6bf8943159e5d33b26c 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
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