-
-
Save Papierkorb/f253edb22df08a13e6d8cba9f44cbc00 to your computer and use it in GitHub Desktop.
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 "benchmark" | |
socket = TCPSocket.new "localhost", 8081 | |
# socket.tcp_nodelay = true | |
# socket.sync = true | |
data = Bytes.new 20 | |
Benchmark.ips do |x| | |
x.report("ping") do | |
socket.write data | |
socket.read_fully data | |
end | |
end |
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 "localhost", 8081 | |
buf = Bytes.new 20 | |
while socket = server.accept | |
# socket.tcp_nodelay = true | |
# socket.sync = true | |
spawn do | |
begin | |
loop do | |
socket.read_fully buf | |
spawn do | |
socket.write buf | |
end | |
end | |
ensure | |
socket.close | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment