Last active
March 3, 2016 18:40
-
-
Save simplay/61a1f271d2e53e8a389a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# client.rb | |
require 'socket' | |
require 'digest/sha1' | |
require 'json' | |
hostname = "localhost" | |
port = 2000 | |
socket = TCPSocket.open(hostname, port) | |
1.times do |i| | |
content = "#{i.to_s}: #{ARGV[0].to_s}" | |
msg = { | |
:header => :mss, | |
:secret => Digest::SHA1.hexdigest(ENV['P_SECRET']), | |
:content => content | |
} | |
j_msg = msg.to_json | |
puts j_msg | |
socket.puts(j_msg) | |
sleep 0.2 | |
end | |
socket.close | |
# server.rb | |
require 'socket' | |
server = TCPServer.open(2000) | |
loop do | |
client = server.accept | |
while line = client.gets | |
puts "received #{line}" | |
end | |
#client.puts("Ping time=#{Time.now.ctime}") | |
#client.puts "closing connection" | |
client.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment