Klient
s = UDPSocket.new
s.send("Hola", 0, 'localhost', 1234)Server
require 'socket'
host = 'localhost'
port = 1234
s = UDPSocket.new
s.bind(nil, port)
loop
text, sender = s.recvfrom(20)
remote_host = sender[3]
puts "#{remote_host} poslal #{text}"
endTabulka C.1. class methods
| method | prototype |
|---|---|
| new | UDPSocket.new(family = AF_INET) → aSession |
| open | UDPSocket.open(family = AF_INET) → aSession |
Tabulka C.2.
| method | prototype |
|---|---|
| bind | aSession.bind(hostName, port) → 0 |
| connect | aSession.connect(hostName, port) → 0 |
| recvfrom | aSession.recvfrom(len [, flags]) → anArray |
| send | aSession.send(aString, flags [, hostName, port]) → aFixnum |
