Skip to content

Instantly share code, notes, and snippets.

@akostadinov
Created February 18, 2019 19:07
Show Gist options
  • Save akostadinov/ee5df9b25e521cd159bbf1b240657ade to your computer and use it in GitHub Desktop.
Save akostadinov/ee5df9b25e521cd159bbf1b240657ade to your computer and use it in GitHub Desktop.
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