Skip to content

Instantly share code, notes, and snippets.

@akostadinov akostadinov/udp.rb
Created Feb 18, 2019

Embed
What would you like to do?
Ruby UDP echo server and client
# echo server
Socket.udp_server_loop(4444) do |data, src|
src.reply data
end
# client
addr = Socket.sockaddr_in(4444, "localhost")
socket = Socket.new(:INET, :DGRAM)
begin
socket.send("hello\n", 0)
puts socket.gets
ensure
socket.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.