Class: OpenWFE::OldSocketListener

Inherits:
TCPServer
  • Object
show all
Defined in:
lib/openwfe/orest/osocket.rb

Overview

This code was blogged about at jmettraux.wordpress.com/2006/06/01/openwfe-ruby/

Instance Method Summary collapse

Constructor Details

#initialize(iface, port) ⇒ OldSocketListener

starts to listen on a given interface (IP) and port



50
51
52
# File 'lib/openwfe/orest/osocket.rb', line 50

def initialize (iface, port)
    super(iface, port)
end

Instance Method Details

#listenObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/openwfe/orest/osocket.rb', line 54

def listen ()
    while (session = accept())
        #
        # how does it scale ?

        s = session.gets

        if s[0..8] != 'xmlCoder '
            session.close
            break
        end

        l = s[9..-1].to_i

        s = session.gets
            #
            # skipping the empty line between the
            # header and the actual workitem

        sXml = ''

        while sXml.length < l
            s = session.gets
            sXml = "#{sXml}#{s}"
        end

        session.print "<ok-reply/>"
        session.close

        yield OpenWFE.xml_decode(xml.root)
    end
end