mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
initial commit using 24 UDP server code
This commit is contained in:
commit
d64833a927
1 changed files with 25 additions and 0 deletions
25
socket.rb
Normal file
25
socket.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
require 'socket'
|
||||
begin
|
||||
# create the UDPSocket object
|
||||
sock = UDPSocket.new
|
||||
|
||||
# bind it to 0.0.0.0 at the given port
|
||||
port = 55443
|
||||
sock.bind "0.0.0.0", port
|
||||
puts "UDP Socket bound to port #{port} and listening."
|
||||
|
||||
# while true loop to keep listening for new packets
|
||||
while true do
|
||||
data, sender = sock.recvfrom 1024
|
||||
# puts "#{sender[3]} sent #{data} on port #{sender[1]}"
|
||||
puts "Recieved #{data.size} from #{sender[3]}"
|
||||
rand_photo_url = "http://d4gpsb1dbo4rf.cloudfront.net/photo#{rand(11)}.jpg"
|
||||
puts "Sending #{rand_photo_url.size} back"
|
||||
sock.send rand_photo_url, 0, sender[3], sender[1]
|
||||
end
|
||||
|
||||
rescue SystemExit, Interrupt => e
|
||||
puts
|
||||
puts "Okay, fine. I'll stop listening."
|
||||
sock.close
|
||||
end
|
Loading…
Reference in a new issue