Dear all,
I am trying to use twisted to build a client and server component,
which will enable inter-controller communication. But there is an error
with pyrt when I tried to excute it.
The following is my simple code:
class ClientProtocol(protocol.Protocol):
def connectionMade(self):
self.transport.write("hello, world!")
def dataReceived(self, data):
"As soon as any data is received, write it back."
print "Server said:", data
self.transport.loseConnection()
def connectionLost(self, reason):
print "connection lost"
class ServerProtocol(protocol.Protocol):
def dataReceived(self, data):
"As soon as any data is received, write it back."
self.transport.write(data)
class InterControllerCommunication( Component ):
def configure( self, configuration ):
global port
arg_len = len( configuration['arguments'] )
if arg_len == 1:
filename = str( configuration['arguments'][0] )
print 'The argument is %s' % filename
logger.info( 'The argument is %s' % filename )
else:
print 'Argument is more than one. Please check the correctness'
# Read the file and code corresponding information
# In Version 1, I only defined port information for debugging
purposes.
flowspec = open( filename, 'r' )
lineString = flowspec.readline()
while True:
lineList = (lineString.split())
if not lineString:
break
lineString = flowspec.readline()
# print (lineList)
# print "lineList: %s" % lineList[1]
if lineList[0] == 'port':
for n in range( 1, len(lineList) ):
port.append( int(lineList[n]) )
print "port: %d" % port[n-1]
logger.info("port: %d" % port[n-1])
# if lineList[0] == 'match:'
# Initialize client and send msg
factoryClient = protocol.ClientFactory()
factoryClient.protocol = ClientProtocol
# first, only interact with controller at 6634
reactor.connectTCP( "localhost",int(port[1]), factoryClient )
# Initialize server and listen to ports
factoryServer = protocol.ServerFactory()
factoryServer.protocol = ServerProtocol
# first, only try to listen to one controller at port 6634
# later, replace with port parameters above, port[0] provides the
server port
reactor.listenTCP( int(port[0]) , factoryServer )
reactor.run()
This component acts as both client and server and it will only
manipulate simple inter-controller communication. It works fine if I
execute it as normal python file. And I would like to plug it in a NOX
component and make it possible to exchange information between controllers.
However there is always an exception reported when reactor.run() is called.
this is the error:
00931|reactor|ERR:Unhandled Error
Traceback (most recent call last):
File "./nox/coreapps/examples/InterControllerProtocol.py", line 217, in
configure
reactor.run()
File "/usr/lib/python2.6/dist-packages/twisted/internet/base.py", line
1170, in run
self.mainLoop()
--- <exception caught here> ---
File "/usr/lib/python2.6/dist-packages/twisted/internet/base.py", line
1182, in mainLoop
self.doIteration(t)
File "./nox/coreapps/pyrt/pyoxidereactor.py", line 129, in doIteration
raise NotImplementedError()
exceptions.NotImplementedError:
00932|reactor|ERR:Unhandled Error
Traceback (most recent call last):
File "./nox/coreapps/examples/InterControllerProtocol.py", line 217, in
configure
reactor.run()
File "/usr/lib/python2.6/dist-packages/twisted/internet/base.py", line
1170, in run
self.mainLoop()
--- <exception caught here> ---
File "/usr/lib/python2.6/dist-packages/twisted/internet/base.py", line
1182, in mainLoop
self.doIteration(t)
File "./nox/coreapps/pyrt/pyoxidereactor.py", line 129, in doIteration
raise NotImplementedError()
exceptions.NotImplementedError:
Moreover, I've found doIteration(./nox/coreapps/pyrt/pyoxidereactor.py)
is actually not implemented. Is this intended or a bug?
Thank you all.
Kai Xiong