Class: Rev::WebSocket

Inherits:
TCPSocket
  • Object
show all
Defined in:
lib/rev/websocket.rb,
lib/rev/websocket/spec.rb

Overview

Direct Known Subclasses

SSLWebSocket

Defined Under Namespace

Modules: Spec75, Spec76 Classes: DummyIO

Constant Summary collapse

HAVE_ENCODING =
false
FRAME_START =
"\x00"
FRAME_END =
"\xFF"
HTTP11_PRASER =

HTTP11_PRASER = Mongrel::HttpParser

Thin::HttpParser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(socket) ⇒ WebSocket

Returns a new instance of WebSocket.



55
56
57
58
59
60
61
62
# File 'lib/rev/websocket.rb', line 55

def initialize(socket)
	super
	@state = :process_handshake
	@data = ::IO::Buffer.new
	@http11 = HTTP11_PRASER.new
	@http11_nbytes = 0
	@request = {DummyIO::KEY => DummyIO.new}
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



25
26
27
# File 'lib/rev/websocket.rb', line 25

def request
  @request
end

Instance Method Details

#on_error(reason) ⇒ Object



22
23
# File 'lib/rev/websocket.rb', line 22

def on_error(reason)
end

#on_message(data) ⇒ Object



19
20
# File 'lib/rev/websocket.rb', line 19

def on_message(data)
end

#on_openObject



16
17
# File 'lib/rev/websocket.rb', line 16

def on_open
end

#on_read(data) ⇒ Object



70
71
72
73
# File 'lib/rev/websocket.rb', line 70

def on_read(data)
	@data << data
	dispatch
end

#on_readableObject



64
65
66
67
68
# File 'lib/rev/websocket.rb', line 64

def on_readable
	super
rescue
	close
end

#send_message(data) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/rev/websocket.rb', line 27

def send_message(data)
	if HAVE_ENCODING
		frame = FRAME_START + data.force_encoding('UTF-8') + FRAME_END
	else
		frame = FRAME_START + data + FRAME_END
	end
	write frame
end