Class: GameMachine::Clients::UdtClient

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

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ UdtClient

Returns a new instance of UdtClient


5
6
7
8
# File 'server/lib/game_machine/clients/udt_client.rb', line 5

def initialize(server)
  @host = Settings.servers.send(server).udt.host
  @port = Settings.servers.send(server).udt.port
end

Instance Method Details

#connectObject


14
15
16
17
18
19
20
# File 'server/lib/game_machine/clients/udt_client.rb', line 14

def connect
  address = JavaLib::InetSocketAddress.new(@host, @port)
  @socket = JavaLib::SocketUDT.new(JavaLib::TypeUDT::DATAGRAM)
  @socket.setBlocking(true)
  @socket.connect(address)
  @socket
end

#disconnectObject


10
11
12
# File 'server/lib/game_machine/clients/udt_client.rb', line 10

def disconnect
  @socket.close
end

#receive(timeout = 0.100) ⇒ Object


26
27
28
29
30
# File 'server/lib/game_machine/clients/udt_client.rb', line 26

def receive(timeout=0.100)
  array = Java::byte[4096].new
  res = @socket.receive(array)
  JavaLib::Arrays.copy_of_range(array,0,res)
end

#send_message(bytes) ⇒ Object


22
23
24
# File 'server/lib/game_machine/clients/udt_client.rb', line 22

def send_message(bytes)
  @socket.send(bytes)
end