Class: Netpump::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/netpump/server.rb

Instance Method Summary collapse

Constructor Details

#initialize(host: "0.0.0.0", port: 10000, proxy_host: "127.0.0.1", proxy_port: 0) ⇒ Server



9
10
11
12
13
14
15
# File 'lib/netpump/server.rb', line 9

def initialize(host: "0.0.0.0", port: 10000, proxy_host: "127.0.0.1", proxy_port: 0)
  @host = host
  @port = port
  @proxy_host = proxy_host
  @proxy_port = proxy_port
  @log = lambda { |msg, **ctx| log(msg, s: true, **ctx) }
end

Instance Method Details

#startObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/netpump/server.rb', line 17

def start
  @log.call "[+] netpump server is starting.", host: @host, port: @port
  start_websocket_server
  proxy = EventMachine.start_server(
    @proxy_host, @proxy_port, EventMachine::Protocols::CONNECT
  ) do |c|
    fail "inactivity timeout" unless c.comm_inactivity_timeout.zero?
  end
  @proxy_port, @proxy_host = Socket.unpack_sockaddr_in(EventMachine.get_sockname(proxy))
end