# DRb::DRbTCPSocket (Class)

In: | drb/drb.rb
Parent: | Object

The default drb protocol.

Communicates over a TCP socket.

## Methods

accept alive? close new open open_server peeraddr recv_reply recv_request send_reply send_request stream uri_option

## Attributes

uri | [R] | Get the URI that we are connected to.

## Public Class methods

open(uri, config)

Open a client connection to `uri` using configuration `config`.

[Source]

    # File drb/drb.rb, line 791
        def self.open(uri, config)
          host, port, option = parse_uri(uri)
          host.untaint
          port.untaint
          soc = TCPSocket.open(host, port)
          self.new(uri, soc, config)
        end

open_server(uri, config)

Open a server listening for connections at `uri` using configuration `config`.

[Source]

    # File drb/drb.rb, line 801
        def self.open_server(uri, config)
          uri = 'druby://:0' unless uri
          host, port, opt = parse_uri(uri)
          if host.size == 0
            soc = TCPServer.open(port)
            host = Socket.gethostname
          else
            soc = TCPServer.open(host, port)
          end
          port = soc.addr[1] if port == 0
          uri = "druby://#{host}:#{port}"
          self.new(uri, soc, config)
        end

uri_option(uri, config)

Parse `uri` into a [uri, option] pair.

[Source]

    # File drb/drb.rb, line 816
        def self.uri_option(uri, config)
          host, port, option = parse_uri(uri)
          return "druby://#{host}:#{port}", option
        end

new(uri, soc, config={})

Create a new DRbTCPSocket instance.

`uri` is the URI we are connected to. `soc` is the tcp socket we are bound to. `config` is our configuration.

[Source]

    # File drb/drb.rb, line 826
        def initialize(uri, soc, config={})
          @uri = uri
          @socket = soc
          @config = config
          @acl = config[:tcp_acl]
          @msg = DRbMessage.new(config)
          set_sockopt(@socket)
        end

## Public Instance methods

peeraddr()

Get the address of our TCP peer (the other end of the socket we are bound to.

[Source]

    # File drb/drb.rb, line 840
        def peeraddr
          @socket.peeraddr
        end

stream()

Get the socket.

[Source]

    # File drb/drb.rb, line 845
        def stream; @socket; end

send_request(ref, msg_id, arg, b)

On the client side, send a request to the server.

[Source]

    # File drb/drb.rb, line 848
        def send_request(ref, msg_id, arg, b)
          @msg.send_request(stream, ref, msg_id, arg, b)
        end

recv_request()

On the server side, receive a request from the client.

[Source]

    # File drb/drb.rb, line 853
        def recv_request
          @msg.recv_request(stream)
        end

send_reply(succ, result)

On the server side, send a reply to the client.

[Source]

    # File drb/drb.rb, line 858
        def send_reply(succ, result)
          @msg.send_reply(stream, succ, result)
        end

recv_reply()

On the client side, receive a reply from the server.

[Source]

    # File drb/drb.rb, line 863
        def recv_reply
          @msg.recv_reply(stream)
        end

close()

Close the connection.

If this is an instance returned by open_server, then this stops listening for new connections altogether. If this is an instance returned by open or by accept, then it closes this particular client-server session.

[Source]

    # File drb/drb.rb, line 875
        def close
          if @socket
            @socket.close
            @socket = nil
          end
        end

accept()

On the server side, for an instance returned by open_server, accept a client connection and return a new instance to handle the server’s side of this client-server session.

[Source]

    # File drb/drb.rb, line 885
        def accept
          while true
            s = @socket.accept
            break if (@acl ? @acl.allow_socket?(s) : true)
            s.close
          end
          self.class.new(nil, s, @config)
        end

alive?()

Check to see if this connection is alive.

[Source]

    # File drb/drb.rb, line 895
        def alive?
          return false unless @socket
          if IO.select([@socket], nil, nil, 0)
            close
            return false
          end
          true
        end

[Validate]