Created
February 8, 2014 13:57
-
-
Save dobestan/8884128 to your computer and use it in GitHub Desktop.
Ruby Socket Client/Server
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' | |
require 'pry' | |
socket = TCPSocket.new 'localhost', 2000 | |
while line = socket.gets | |
puts line | |
end | |
socket.close |
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" | |
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