Skip to content

Commit

Permalink
A ruby connector for udp to get things running faster
Browse files Browse the repository at this point in the history
Initialize with 
require './udp_connector'
connector = UdpConnector.new([host], [port])

send and receive messages:
 @connector.send_message([message])
 [message] = @connector.receive_message
  • Loading branch information
jukecraft committed Aug 3, 2013
1 parent a9b202c commit daa9a97
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions udp_connector
@@ -0,0 +1,18 @@
require 'socket'

class UdpConnector

def initialize(host, port)
@socket = UDPSocket.new
@socket.connect(host, port)
end

def send_message(message)
@socket.send(message, 0)
end

def receive_message
msg, sender = @socket.recvfrom(10000)
msg
end
end

0 comments on commit daa9a97

Please sign in to comment.