Class: GameMachine::Clients::UdpClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port) ⇒ UdpClient

Returns a new instance of UdpClient


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

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

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host


8
9
10
# File 'server/lib/game_machine/clients/udp_client.rb', line 8

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port


8
9
10
# File 'server/lib/game_machine/clients/udp_client.rb', line 8

def port
  @port
end

#socketObject (readonly)

Returns the value of attribute socket


8
9
10
# File 'server/lib/game_machine/clients/udp_client.rb', line 8

def socket
  @socket
end

Instance Method Details

#receive_messageObject


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

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

#send_message(message) ⇒ Object


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

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