Skip to content

Instantly share code, notes, and snippets.

Created November 23, 2016 22:42
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 anonymous/7da948629ea906d1f58c252bc95e06ff to your computer and use it in GitHub Desktop.
Save anonymous/7da948629ea906d1f58c252bc95e06ff to your computer and use it in GitHub Desktop.
require 'socket' # Get sockets from stdlib
require "json"
server = TCPServer.open(2000) # Socket to listen on port 2000
loop { # Servers run forever
client = server.accept # Wait for a client to connect
my_hash = { :numbers => [1, 3, 6], :text => "test"}
client.puts(JSON.generate my_hash) # Send the json text to the client
client.close # Disconnect from the client
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment