wamp-client 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,8 +18,8 @@ module WAMP
18
18
  TYPEID_EVENT = 8
19
19
 
20
20
 
21
- def initialize(uri, options=nil)
22
- options ||= {:subprotocols => ["wamp"]}
21
+ def initialize(uri, options={})
22
+ options = {:subprotocols => ["wamp"]}.merge(options)
23
23
  @session_id = nil
24
24
  @ws = Net::WS.new(uri, options)
25
25
  @subscriptions = {}
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module WAMP
3
3
  class Client
4
- VERSION = "0.0.4"
4
+ VERSION = "0.0.5"
5
5
  end
6
6
  end
@@ -1,3 +1,5 @@
1
+ #!/usr/bin/env python2.7 -u -Wall
2
+
1
3
  import sys
2
4
 
3
5
  from twisted.internet import reactor
@@ -18,7 +20,7 @@ class RpcServerProtocol(WampServerProtocol):
18
20
 
19
21
  if __name__ == '__main__':
20
22
  factory = WampServerFactory("ws://localhost:9001", debug=True)
21
- factory.protocol = RpcServerProtocol
23
+ factory.protocol = WampServerProtocol
22
24
  log.startLogging(sys.stdout)
23
25
  listenWS(factory)
24
26
  print "Here we go"
@@ -9,49 +9,48 @@ describe WAMP::Client do
9
9
  def with_echo_server(&block)
10
10
  echo_server_path = File.expand_path("../support/echo_server.py",
11
11
  File.dirname(__FILE__))
12
+ wamp_server_path = File.expand_path("../support/wamp_server.py",
13
+ File.dirname(__FILE__))
12
14
 
13
- Open3.popen3(echo_server_path) do |stdin, stdout, stderr|
15
+ puts "bringing up echo server"
16
+ Open3.popen3(wamp_server_path) do |stdin, stdout, stderr, wait_thr|
17
+ pid = wait_thr.pid
14
18
  stdout.readline # the readline tells us the server is up
15
- yield "localhost", 9001
19
+ block.call("localhost", 9001)
20
+ puts "tearing down echo server"
21
+ Process.kill("TERM", pid)
16
22
  end
17
23
  end
18
24
 
19
- # it "should be sane" do
20
- # true.must_equal true
21
- # end
22
-
23
25
  it "can send and receive message" do
24
26
  CHANNEL = "/mpd/test"
25
27
 
26
28
  host = "localhost"; port = 9001
29
+ with_echo_server do |host, port|
30
+ listener = WAMP::Client.new("ws://#{host}:#{port}")
31
+ listener.open
32
+ listener.subscribe(CHANNEL, proc {|x| $stderr.puts "Rx: %p" % [x]})
27
33
 
28
- listener = WAMP::Client.new("ws://#{host}:#{port}",
29
- :subprotocols => ["wamp"])
30
- listener.open
31
- listener.subscribe(CHANNEL, proc {|x| $stderr.puts "Rx: %p" % [x]})
34
+ puts "listener subscribed"
32
35
 
33
- puts "listener subscribed"
34
36
 
37
+ client = WAMP::Client.new("ws://#{host}:#{port}").tap {|x| x.open}
38
+ client.publish(CHANNEL, "testing 1 2 3")
35
39
 
36
- client = WAMP::Client.new("ws://#{host}:#{port}",
37
- :subprotocols => ["wamp"])
38
- puts client.open
39
- client.publish(CHANNEL, "testing 1 2 3")
40
+ puts "checking..."
41
+ listener.check(0.1)
40
42
 
41
- puts "checking..."
42
- listener.check(0.1)
43
+ client.publish(CHANNEL, "∆AIMON")
43
44
 
44
- client.publish(CHANNEL, "∆AIMON")
45
+ puts "checking..."
46
+ listener.check(0.1)
45
47
 
46
- puts "checking..."
47
- listener.check(0.1)
48
+ client.publish(CHANNEL, {"file" => "∆AIMON"})
48
49
 
49
- client.publish(CHANNEL, {"file" => "∆AIMON"})
50
+ puts "checking..."
51
+ listener.check(0.1)
50
52
 
51
- puts "checking..."
52
- listener.check(0.1)
53
-
54
- config = StringIO.new <<EOF
53
+ config = StringIO.new <<EOF
55
54
  development:
56
55
  hostname: admin@localhost
57
56
  port: 6601
@@ -61,16 +60,17 @@ test:
61
60
  port: 6601
62
61
  EOF
63
62
 
64
- rmpd = Rmpd::Connection.new(config)
65
- pi = rmpd.search("artist", "aimon", "title", "current")
66
- client.publish(CHANNEL, pi)
63
+ rmpd = Rmpd::Connection.new(config)
64
+ pi = rmpd.search("artist", "aimon", "title", "current")
65
+ client.publish(CHANNEL, pi)
67
66
 
68
- puts "checking..."
69
- listener.check(0.1)
67
+ puts "checking..."
68
+ listener.check(0.1)
70
69
 
71
- puts "closing"
72
- client.close
73
- listener.close
70
+ puts "closing"
71
+ client.close
72
+ listener.close
73
+ end
74
74
 
75
75
  end
76
76
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wamp-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-28 00:00:00.000000000 Z
12
+ date: 2013-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yajl-ruby
@@ -171,7 +171,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
171
  version: '0'
172
172
  segments:
173
173
  - 0
174
- hash: 4170054363117719336
174
+ hash: -4201952591777948766
175
175
  required_rubygems_version: !ruby/object:Gem::Requirement
176
176
  none: false
177
177
  requirements:
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
180
  version: '0'
181
181
  segments:
182
182
  - 0
183
- hash: 4170054363117719336
183
+ hash: -4201952591777948766
184
184
  requirements: []
185
185
  rubyforge_project:
186
186
  rubygems_version: 1.8.23