quarta-feira, 18 de agosto de 2010

Simple Twisted connector

Estou come'cando a gostar deste python, fiz alguns testes com o twisted, estou bem acostumado com o ASIO. foi bem facil entender o funcionamento basico.

vejam o conector que fiz para inciar meus testes ;)

# Clebson Derivan ( cderivan@gmail.com )
#
fixTestBot - provides FIX protocol bussiness level test automation.

# twisted imports
import sys
from twisted.internet import reactor, protocol
from twisted.python import log

class Protocol(protocol.Protocol):
def connectionMade(self):
self.transport.write(
"Twisted server v000\r\n")
print "We are connected"

def dataReceived(self, raw):
print "msg received: ", raw

class Factory(protocol.ReconnectingClientFactory):

def buildProtocol(self, addr):
self.resetDelay()
return Protocol()

if __name__ == "__main__":

log.startLogging(sys.stdout)

f
= Factory()
reactor.connectTCP(
"127.0.0.1", 9000, f )
reactor.run()


e roda bonitinho, simples e rapido, vejam que ele incrementa automatico o tempo de recone'cao.


C:\devel\python\fixTestSDK>connector.py
2010-08-20 16:50:42-0300 [-] Log opened.
2010-08-20 16:50:42-0300 [-] Starting factory <__main__.factory>
2010-08-20 16:50:43-0300 [Uninitialized]
will retry in 2 seconds

2010-08-20 16:50:43-0300 [Uninitialized] Stopping factory <__main__.factory>
2010-08-20 16:50:45-0300 [-] Starting factory <__main__.factory>
2010-08-20 16:50:46-0300 [Uninitialized]
will retry in 9 seconds

2010-08-20 16:50:46-0300 [Uninitialized] Stopping factory <__main__.factory>
2010-08-20 16:50:55-0300 [-] Starting factory <__main__.factory>
2010-08-20 16:50:55-0300 [Uninitialized] We are connected

se quizer testar, usa o netcat

C:\Documents and Settings\bzero>nc -L -p 9000
Twisted server v000


2 comentários:

  1. Parabéns pelo blog Clebson!

    Tem o meu apoio!

    ResponderExcluir
  2. valeu, ate que ta sendo sussa mexer com ele. ao menos agora nas ferias :D

    ResponderExcluir