Skip to content

Instantly share code, notes, and snippets.

@vigram
Created January 9, 2015 07:05
Show Gist options
  • Save vigram/16660307a3ad01dbc9cc to your computer and use it in GitHub Desktop.
Save vigram/16660307a3ad01dbc9cc to your computer and use it in GitHub Desktop.
Simple TCP oriented messaging system
client-side:
~~~~~~~~~~~
require 'socket'
hostname = 'localhost'
port = 2000
s = TCPSocket.open(hostname, port)
while line = s.gets
puts line.chop
end
server-side:
~~~~~~~~~~~
require 'socket'
server = TCPServer.open(2000)
client = server.accept
client.puts "Hi I'm here !!!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment