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