Class: GameMachine::Clients::Client

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ Client

Returns a new instance of Client


8
9
10
11
12
13
# File 'server/lib/game_machine/clients/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

Class Method Details

.connect_udtObject


29
30
31
32
33
34
35
# File 'server/lib/game_machine/clients/client.rb', line 29

def self.connect_udt
  address = JavaLib::InetSocketAddress.new(Settings.servers.seed01.udt_host, Settings.servers.seed01.udt_port)
  s = JavaLib::SocketUDT.new(JavaLib::TypeUDT::DATAGRAM)
  s.setBlocking(true)
  s.connect(address)
  s
end

.http_post(path, data) ⇒ Object


23
24
25
26
27
# File 'server/lib/game_machine/clients/client.rb', line 23

def self.http_post(path,data)
  uri = URI.parse("http://localhost:8080#{path}")
  response = Net::HTTP.post_form(uri, data)
  response.body
end

.send_udt(s, bytes) ⇒ Object


37
38
39
40
41
42
# File 'server/lib/game_machine/clients/client.rb', line 37

def self.send_udt(s,bytes)
  s.send(bytes)
  array = Java::byte[4096].new
  l = s.receive(array)
  JavaLib::Arrays.copy_of_range(array,0,l)
end

Instance Method Details

#receive_messageObject


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

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

#send_message(message) ⇒ Object


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

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