Class: DRbWebSocket::Server

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

Overview

A protocol instance from DrbWebSocket::Protocol.open_server.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, socket, config = {}) ⇒ Server

Returns a new instance of Server.

Raises:

  • (ArgumentError)


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

def initialize(uri, socket, config = {})
  raise ArgumentError, "socket Must respond to :to_io" unless socket.respond_to?(:to_io)

  @uri = uri
  @socket = socket
  @config = config
end

Instance Attribute Details

#uriObject (readonly)

Get the URI for this server.



7
8
9
# File 'lib/drb_web_socket/server.rb', line 7

def uri
  @uri
end

Instance Method Details

#acceptObject

Accept a new connection to the server. Returns a protocol instance capable of communicating with the client.



19
20
21
22
# File 'lib/drb_web_socket/server.rb', line 19

def accept
  socket = @socket.accept
  ConnectionToClient.new(@uri, socket, @config)
end

#closeObject

Close the server connection.



25
26
27
28
29
30
# File 'lib/drb_web_socket/server.rb', line 25

def close
  return unless @socket

  @socket.close
  @socket = nil
end