File: echo_client.rb

package info (click to toggle)
ruby-celluloid-io 0.16.2-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, stretch
  • size: 432 kB
  • ctags: 189
  • sloc: ruby: 1,727; makefile: 6
file content (25 lines) | stat: -rw-r--r-- 480 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
#!/usr/bin/env ruby

require 'rubygems'
require 'bundler/setup'
require 'celluloid/io'

class EchoClient
  include Celluloid::IO

  def initialize(host, port)
    puts "*** Connecting to echo server on #{host}:#{port}"

    # This is actually creating a Celluloid::IO::TCPSocket
    @socket = TCPSocket.new(host, port)
  end

  def echo(s)
    @socket.write(s)
    @socket.readpartial(4096)
  end

end

client = EchoClient.new("127.0.0.1", 1234)
puts client.echo("TEST FOR ECHO")