Skip to content

Instantly share code, notes, and snippets.

@aachyee
Forked from akostadinov/udp.rb
Last active September 6, 2021 23:41
Show Gist options
  • Select an option

  • Save aachyee/af7ce0f2e14936723158910d1d53ff32 to your computer and use it in GitHub Desktop.

Select an option

Save aachyee/af7ce0f2e14936723158910d1d53ff32 to your computer and use it in GitHub Desktop.
Ruby UDP echo server and client
require 'socket'
# 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