Class: GameMachine::Clients::Client
- Inherits:
-
Object
- Object
- GameMachine::Clients::Client
- Defined in:
- server/lib/game_machine/clients/client.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(server) ⇒ Client
constructor
A new instance of Client.
- #receive_message ⇒ Object
- #send_message(message) ⇒ Object
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_udt ⇒ Object
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_message ⇒ Object
19 20 21 |
# File 'server/lib/game_machine/clients/client.rb', line 19 def @socket.recvfrom(1024)[0] end |
#send_message(message) ⇒ Object
15 16 17 |
# File 'server/lib/game_machine/clients/client.rb', line 15 def () @socket.send(String.from_java_bytes(),@host,@port) end |