Esempio n. 1
0
 def connect_or_close (addr):
         if addr == None:
                 dispatcher.handle_close ()
         else:
                 async_client.connect (
                         dispatcher, addr, timeout, socket.AF_INET
                         )
Esempio n. 2
0
def connect (
        dispatcher, name, timeout=3.0, 
        resolved=ip_resolved, resolve=dns_A_resolve
        ):
        "resolve and maybe connect a dispatcher, close on error"
        assert not dispatcher.connected
        addr = resolved (name)
        if addr != None:
                return async_client.connect (
                        dispatcher, addr, timeout, socket.AF_INET
                        )

        if resolve == None:
                dispatcher.handle_close ()
                return False
        
        def connect_or_close (addr):
                if addr == None:
                        dispatcher.handle_close ()
                else:
                        async_client.connect (
                                dispatcher, addr, timeout, socket.AF_INET
                                )
                                
        resolve (name, connect_or_close)
        return True
Esempio n. 3
0
def test_unmanaged():
    loginfo.log('test_unmanaged')
    for host in ('999.999.999.999', '127.0.0.2', '127.0.0.1'):
        dispatcher = async_chat.Dispatcher()
        if async_client.connect(dispatcher, (host, 80), 3):
            dispatcher.async_chat_push('GET /prompt.xml HTTP/1.1\r\n'
                                       'Host: %s\r\n'
                                       '\r\n' % host)
def test_unmanaged ():
        loginfo.log ('test_unmanaged')
        for host in ('999.999.999.999', '127.0.0.2', '127.0.0.1'):
                dispatcher = async_chat.Dispatcher ()
                if async_client.connect (dispatcher, (host, 80), 3):
                        dispatcher.async_chat_push (
                                'GET /prompt.xml HTTP/1.1\r\n'
                                'Host: %s\r\n'
                                '\r\n' % host
                                )
Esempio n. 5
0
def connect(dispatcher,
            name,
            timeout=3.0,
            resolved=ip_resolved,
            resolve=dns_A_resolve):
    "resolve and maybe connect a dispatcher, close on error"
    assert not dispatcher.connected
    addr = resolved(name)
    if addr != None:
        return async_client.connect(dispatcher, addr, timeout, socket.AF_INET)

    if resolve == None:
        dispatcher.handle_close()
        return False

    def connect_or_close(addr):
        if addr == None:
            dispatcher.handle_close()
        else:
            async_client.connect(dispatcher, addr, timeout, socket.AF_INET)

    resolve(name, connect_or_close)
    return True
Esempio n. 6
0
def connect(obj, ip, port):
    ''' connect a client '''
    return async_client.connect(Dispatcher(obj), (ip, port), 3)
Esempio n. 7
0
    ac_in_buffer_size = 1024
    ac_out_buffer_size = 1<<14
    
    def async_net_continue (self, string):
        code = string[0]
        if code == 'K':
            self.log (string)
        elif code == 'Z':
            self.log (string, 'temporary failure')
        elif code == 'D':
            self.log (string, 'permanent failure')
        else:
            self.log (string, 'protocol error')

qmtp = QMTP ()
if async_client.connect (qmt, ('127.0.0.1', 209), 3):
    push = qmtp.async_net_push
    push ((
        'Subject: Hello\n\nHello who?', 
        'from@me', 
        netstring.encode (('to@you', ))
        ))
    push ((
        'Subject: Re: Hello\n\nHello World!', 
        '',
        netstring.encode (('to@you', 'cc@somebody'))
        ))
    async_loop.dispatch ()
    
    
# Logging PIRP client
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# You should have received a copy of the GNU General Public License
# along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA

"http://laurentszyster.be/blog/tutorial-one/"

# A Simple Client

from allegra import async_loop, async_chat, collector, async_client

dispatcher = async_chat.Dispatcher()
if async_client.connect(dispatcher, ("66.249.91.99", 80), 3):
    dispatcher.async_chat_push("GET / HTTP/1.0\r\n" "\r\n")
    collector.bind(dispatcher, collector.LOGINFO)
async_loop.dispatch()


# Adding Features

from allegra import finalization, async_limits, synchronized

dispatcher = async_chat.Dispatcher()
if async_client.connect(dispatcher, ("66.249.91.99", 80), 3):
    dispatcher.async_chat_push("GET / HTTP/1.1\r\n" "Host: 66.249.91.99\r\n" "Connection: keep-alive\r\n" "\r\n")
    collector.bind(dispatcher, synchronized.File_collector("response.txt"))
    async_limits.limit_recv(dispatcher, 3, 1, (lambda: 1 << 13))
    dispatcher.finalization = lambda finalized: finalized.log('bytes in="%d"' % finalized.ac_in_meter)
Esempio n. 9
0
import sys

from allegra import async_loop, async_core, async_client

try:
    TCP_CONCURRENT = max(1, int(sys.argv[1]))
except:
    TCP_CONCURRENT = 64
try:
    TCP_WINDOW_SIZE = 1 << min(14, int(sys.argv[2]))
except:
    TCP_WINDOW_SIZE = 1 << 14
TCP_OVERFLOW_DATA = 'x' * (TCP_WINDOW_SIZE * 2)


class Flaking(async_core.Dispatcher):
    def handle_write(self):
        self.send(TCP_OVERFLOW_DATA)

    def handle_read(self):
        self.recv(TCP_WINDOW_SIZE / 2)


for i in range(TCP_CONCURRENT):
    async_client.connect(Flaking(), ('127.0.0.1', 1234), 3)

async_loop.dispatch()
Esempio n. 10
0
    ac_out_buffer_size = 1 << 14

    def async_net_continue(self, string):
        code = string[0]
        if code == 'K':
            self.log(string)
        elif code == 'Z':
            self.log(string, 'temporary failure')
        elif code == 'D':
            self.log(string, 'permanent failure')
        else:
            self.log(string, 'protocol error')


qmtp = QMTP()
if async_client.connect(qmt, ('127.0.0.1', 209), 3):
    push = qmtp.async_net_push
    push(('Subject: Hello\n\nHello who?', 'from@me',
          netstring.encode(('to@you', ))))
    push(('Subject: Re: Hello\n\nHello World!', '',
          netstring.encode(('to@you', 'cc@somebody'))))
    async_loop.dispatch()

# Logging PIRP client


class PIRP(async_net.Dispatcher):

    ac_in_buffer_size = 1 << 14
    ac_out_buffer_size = 2048
Esempio n. 11
0
 def __init__ (self, addr, pipe, timeout=3):
         self.pns_pipe = pipe
         Dispatcher.__init__ (self)
         async_client.connect (self, addr, timeout)
         self.pns_commands[('', '', '')] = [self.pns_peer]
Esempio n. 12
0
 def connect_or_close(addr):
     if addr == None:
         dispatcher.handle_close()
     else:
         async_client.connect(dispatcher, addr, timeout, socket.AF_INET)
Esempio n. 13
0
def connect(obj, ip, port):
    ''' connect a client '''
    return async_client.connect( Dispatcher(obj), (ip, port), 3)
Esempio n. 14
0
 def __init__(self, addr, pipe, timeout=3):
     self.pns_pipe = pipe
     Dispatcher.__init__(self)
     async_client.connect(self, addr, timeout)
     self.pns_commands[('', '', '')] = [self.pns_peer]
import sys

from allegra import async_loop, async_core, async_client

try:
        TCP_CONCURRENT = max (1, int (sys.argv[1]))
except:
        TCP_CONCURRENT = 64
try:
        TCP_WINDOW_SIZE = 1 << min (14, int (sys.argv[2]))
except:
        TCP_WINDOW_SIZE = 1 << 14
TCP_OVERFLOW_DATA = 'x' * (TCP_WINDOW_SIZE*2)

class Flaking (async_core.Dispatcher):
        
        def handle_write (self):
                self.send (TCP_OVERFLOW_DATA)
                
        def handle_read (self):
                self.recv (TCP_WINDOW_SIZE/2)
                

for i in range (TCP_CONCURRENT):
        async_client.connect (Flaking (), ('127.0.0.1', 1234), 3)

async_loop.dispatch ()