UDP socket

P

PeeF

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
 
B

Bill Kelly

Hi,

From: "PeeF said:
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
 
P

Peefh

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? :/
Newbies should always relearn Kernel stuff before starting network
programming...
Thank you very much!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,371
Latest member
Brkaa

Latest Threads

Top