File: echo_unix_client.rb

package info (click to toggle)
ruby-celluloid-io 0.15.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 352 kB
  • ctags: 164
  • sloc: ruby: 1,610; makefile: 5
file content (29 lines) | stat: -rw-r--r-- 550 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require 'bundler/setup'
require 'celluloid/io'

class EchoUNIXClient
  include Celluloid::IO
  finalizer :finalize

  def initialize(socket_path)
    puts "*** connecting to #{socket_path}"
    @socket_path = socket_path
    @socket = UNIXSocket.open(socket_path)
  end

  def echo(msg)
    puts "*** send to server: '#{msg}'"
    @socket.puts(msg)
    data = @socket.readline.chomp
    puts "*** server unswer '#{data}'"
    data
  end

  def finalize
    @socket.close if @socket
  end

end

c = EchoUNIXClient.new("/tmp/sock_test")
c.echo("DATA")