websocket-client 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/websocket_client/client.rb +3 -0
- data/lib/websocket_client/ietf_00.rb +26 -1
- metadata +3 -3
@@ -42,7 +42,9 @@ module WebSocketClient
|
|
42
42
|
|
43
43
|
def connect(&block)
|
44
44
|
@socket = TCPSocket.open(uri.host, uri.port)
|
45
|
+
puts "> handshaking"
|
45
46
|
@handshake = @handshake_class.new( uri, @socket )
|
47
|
+
puts "> handshook"
|
46
48
|
|
47
49
|
start_handler
|
48
50
|
|
@@ -74,6 +76,7 @@ module WebSocketClient
|
|
74
76
|
if ( block )
|
75
77
|
@on_message_handler = block
|
76
78
|
else
|
79
|
+
puts "> on_message #{msg}"
|
77
80
|
@on_message_handler.call( msg ) if @on_message_handler
|
78
81
|
end
|
79
82
|
end
|
@@ -7,9 +7,11 @@ module WebSocketClient
|
|
7
7
|
class Ietf00
|
8
8
|
|
9
9
|
def initialize(uri, socket)
|
10
|
+
puts "initialize for #{socket}"
|
10
11
|
@socket = socket
|
11
12
|
key1, key2, key3, solution = generate_keys()
|
12
13
|
|
14
|
+
puts "> sending prolog"
|
13
15
|
@socket.puts "GET #{uri.path} HTTP/1.1"
|
14
16
|
@socket.puts "Host: #{uri.host}"
|
15
17
|
@socket.puts "Connection: upgrade"
|
@@ -24,10 +26,14 @@ module WebSocketClient
|
|
24
26
|
@socket.flush
|
25
27
|
|
26
28
|
while ( ! @socket.eof? )
|
27
|
-
line =
|
29
|
+
line = readline( socket )
|
30
|
+
puts ">> #{line}"
|
28
31
|
break if ( line.strip == '' )
|
29
32
|
end
|
33
|
+
|
30
34
|
challenge = @socket.read( 16 )
|
35
|
+
|
36
|
+
puts "> challenge-response #{challenge}"
|
31
37
|
if ( challenge == solution )
|
32
38
|
puts "success!"
|
33
39
|
end
|
@@ -35,6 +41,25 @@ module WebSocketClient
|
|
35
41
|
#dump 'challenge', challenge
|
36
42
|
end
|
37
43
|
|
44
|
+
def readline(socket)
|
45
|
+
line = ''
|
46
|
+
while ( ! socket.eof? )
|
47
|
+
if ( socket.respond_to? :getbyte )
|
48
|
+
c = socket.getbyte
|
49
|
+
else
|
50
|
+
c = socket.getc
|
51
|
+
end
|
52
|
+
puts "> #{c} #{c.class} #{c == '\n'}"
|
53
|
+
|
54
|
+
line << c
|
55
|
+
|
56
|
+
if ( c == 10 )
|
57
|
+
break
|
58
|
+
end
|
59
|
+
end
|
60
|
+
line
|
61
|
+
end
|
62
|
+
|
38
63
|
def encode_text_message(msg)
|
39
64
|
@socket.putc 0x00
|
40
65
|
@socket.print msg
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: websocket-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 6
|
10
|
+
version: 0.1.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- The TorqueBox Team
|