UDP socket

Hello.

I’m looking for the source code of any existing and running program whitch
makes use of UDP Sockets.
Please could you help me to find some?

Thank you.
PeeF

Hi,

Hello.

I’m looking for the source code of any existing and running program whitch
makes use of UDP Sockets.
Please could you help me to find some?

I use this to send commands (status and rcon) to Quake 2 servers:

UDP_RECV_TIMEOUT = 3 # seconds

def q2cmd(str)
resp, sock = nil, nil
begin
cmd = “\377\377\377\377#{str}\0”
sock = UDPSocket.open
sock.send(cmd, 0, @server_addr, @server_port)
resp = if select([sock], nil, nil, UDP_RECV_TIMEOUT)
sock.recvfrom(65536)
end
if resp
resp[0] = resp[0][4…-1] # trim quake’s leading 0xffffffff
end
rescue IOError, SystemCallError
ensure
sock.close if sock
end
resp
end

Hope this helps,

Regards,

Bill

···

From: “PeeF” peefh@wanadooZZZ.fr

I use this to send commands (status and rcon) to Quake 2 servers:

UDP_RECV_TIMEOUT = 3 # seconds

def q2cmd(str)
resp, sock = nil, nil
begin
cmd = “\377\377\377\377#{str}\0”
sock = UDPSocket.open
sock.send(cmd, 0, @server_addr, @server_port)
resp = if select([sock], nil, nil, UDP_RECV_TIMEOUT)
sock.recvfrom(65536)
end
if resp
resp[0] = resp[0][4…-1] # trim quake’s leading 0xffffffff
end
rescue IOError, SystemCallError
ensure
sock.close if sock
end
resp
end

Yes! Why didn’t I remember this select command? :confused:
Newbies should always relearn Kernel stuff before starting network
programming…
Thank you very much!

···


Ceci est une signature automatique de MesNews.
Site : http://mesnews.no-ip.com