Skip to content

Instantly share code, notes, and snippets.

@dobestan
Created February 8, 2014 13:57
Show Gist options
  • Save dobestan/8884128 to your computer and use it in GitHub Desktop.
Save dobestan/8884128 to your computer and use it in GitHub Desktop.
Ruby Socket Client/Server
require 'socket'
require 'pry'
socket = TCPSocket.new 'localhost', 2000
while line = socket.gets
puts line
end
socket.close
require "socket"
server = TCPServer.new 2000
x = 1
while true
puts "Waiting for the client #{x}..."
client = server.accept
client.puts "Welcome"
client.puts "Time is #{Time.now}"
client.close
x += 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment