Last active
February 27, 2017 12:37
-
-
Save rkotov93/96c689906ea32046dbe6e449dd0334ca 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
require 'socket' | |
# read 1024 bytes from /dev/urandom and replace non UTF-8 cahracters with '' | |
seq = %x(dd if=/dev/urandom bs=1024 count=1) | |
seq.encode!('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '') | |
seq.gsub!(/\s+/, "") | |
# Send urandom data to the server via socket | |
socket = TCPSocket.open('localhost', 7563) | |
socket.print(seq) | |
socket.close |
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
require 'socket' | |
server = TCPServer.new 'localhost', 7563 | |
puts 'Listen to localhost:7563' | |
loop do | |
# Start socket connection handling in Thread | |
Thread.start(server.accept) do |client| | |
puts '-' * 50 | |
puts "START SOCKET CONNECTION #{Time.now}" | |
puts '-' * 50 | |
# Print request content to console | |
while line = client.gets | |
puts line | |
end | |
puts '-' * 50 | |
puts "FINISH SOCKET CONNECTION #{Time.now}" | |
puts '-' * 50 | |
client.close | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment