Class: GameMachine::Clients::UdpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/game_machine/clients/udp_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ UdpClient

Returns a new instance of UdpClient.



8
9
10
11
12
13
# File 'lib/game_machine/clients/udp_client.rb', line 8

def initialize(server)
  @host = Settings.servers.send(server).udp_host
  @port = Settings.servers.send(server).udp_port
  @socket = UDPSocket.new
  @socket.connect(@host,@port)
end

Instance Method Details

#receive_messageObject



19
20
21
# File 'lib/game_machine/clients/udp_client.rb', line 19

def receive_message
  @socket.recvfrom(1024)[0]
end

#send_message(message) ⇒ Object



15
16
17
# File 'lib/game_machine/clients/udp_client.rb', line 15

def send_message(message)
  @socket.send(message,@host,@port)
end