require 'socket'
$port = 4321
sThread = Thread.start do # run server in a thread
server = UDPSocket.open
server.bind(nil, $port)
2.times {
p server.recvfrom(64)
}
end
# Ad-hoc client
UDPSocket.open.send("ad hoc", 0, 'localhost', $port)
# Connection vased client
sock = UDPSocket.open
sock.connect('localhost', $port)
sock.send("connection-based", 0)
sThread.join