wideact 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +8 -0
  3. data/lib/wideact.rb +6 -0
  4. data/lib/wideact/client.rb +58 -0
  5. metadata +48 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d00f241d3326b327c4499124a8abf7f1d7134c83
4
+ data.tar.gz: eac012a8ba962a0e9bf5a8da543118539c40697a
5
+ SHA512:
6
+ metadata.gz: 240de02f1b3ebc2997d7b427bf0a91d2ffc57f5411bdb71cd2d11485787ddac79aa9979559c4654f29a7c8ace6f00d9bcd50de62fba678897757c27958044d01
7
+ data.tar.gz: 0a73e4f895b8a8af3738d5aed95be41af1da2b2eacb24a3b293fd6982ff0fd14c0e0e3dd2bc8c3a02a94461f9faf6b81c9804af3b95dda4fd2733e191e753b2c
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2016 Gavrilov Miroslav
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/lib/wideact.rb ADDED
@@ -0,0 +1,6 @@
1
+
2
+ module Wideact
3
+ __VERSION = '0.0.1'
4
+ end
5
+
6
+ require "wideact/client.rb"
@@ -0,0 +1,58 @@
1
+
2
+ require 'socket'
3
+
4
+ class Wideact::Client
5
+ def initialize(name, args = { host: "localhost", port: 40444, server: nil })
6
+ @host = args[:host]
7
+ @port = args[:port]
8
+ if args[:server].nil?
9
+ @client_socket = TCPSocket.new @host, @port
10
+ else
11
+ @client_socket = args[:server]
12
+ end
13
+
14
+ @listeners = []
15
+
16
+ @from_server = Thread.new {
17
+ loop do
18
+ while data = @client_socket.gets
19
+ if data.start_with?("MESSAGE")
20
+ parse(data)
21
+ end
22
+ end
23
+ end
24
+ }
25
+
26
+ @from_server.run
27
+
28
+ connect(name)
29
+ end
30
+
31
+ def parse(data)
32
+ message = data.split(" ", 3)
33
+
34
+ return if message.length < 3
35
+
36
+ @listeners.each do |listener|
37
+ listener.call(message[1], message[2])
38
+ end
39
+ end
40
+
41
+ def connect(name)
42
+ @client_socket.puts "CONNECT #{name}"
43
+ end
44
+
45
+ def message(receiver, message)
46
+ @client_socket.puts "MESSAGE #{receiver} #{message}"
47
+ end
48
+
49
+ def add_listener(&listener)
50
+ @listeners.push(listener)
51
+ end
52
+
53
+ def close
54
+ @from_server.stop
55
+ @client_socket.close
56
+ end
57
+ end
58
+
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wideact
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Gavrilov Miroslav
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: If you need a realtime way to communicate with another application, even
14
+ if in another language, this is the gem for you. Actually, this is the ruby client,
15
+ but you can find the server on github.
16
+ email: gavrilov.miroslav@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - LICENSE
22
+ - lib/wideact.rb
23
+ - lib/wideact/client.rb
24
+ homepage: https://github.com/gavrilovmiroslav/wideact
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.5.1
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: An interlingual actor system based on named messaging.
48
+ test_files: []