Hey there,
 
Setup:
-i got a Server which is running a Delphi application on Windows7 using WinSocketComponents
-i got a Client (Raspberry Pi) which is running my python client application with twisted
-the server collects data which the client is sending, sometimes the server sends back
 
Problem:
-the client connects and starts sending, the communication works fine at first
-after some time (rigth now i see no correlation or principle) the server won't get any messages anymore, although the client keeps sending (or at least the client keeps calling the sendMessage() function
->the client is still able to receive messages!
 
I have no clue whats happening. There is no suspicious behavior nor a exception call.
When i stop the client, the server recognizes a disconnect, but before, no disconnect is recognized.
Has anyone of you an idea or does anyone see a mistake in the design of my Factory or Protocol?
Are there known problems with the combination of python twisted and WinSocket of Windows?
 
Here are both:
 
class ControllerProtocol(Protocol):
    def connectionMade(self):
        # send Greeting
        self.factory.isConnected = True
        self.transport.write("Hi there Mother.")
        self.factory.resetDelay()
        #self.RefToOperator.debug('0 |-> ConnectionMade.')
            
    def dataReceived(self, data):
        "Parse received data and send corresponding Message."
        self.transport.write(self.factory.reactOnReceive(data))
                
    def connectionLost(self, reason):
        #try to reconnect    
        self.factory.isConnected = False      
        #self.RefToOperator.debug( "0 Connection lost")
        
    def sendMessage(self, data):
        self.factory.RefToOperator.debug('2 Sending Message.')
        self.transport.write(data)

class Communicator(ReconnectingClientFactory):
    protocol = ControllerProtocol

    def __init__(self, operator):
        """
        :param operator: Operator
        :type self.RefToOperator: Operator
        """
        self.isConnected       = False  
        self.connectedProtocol = None
        self.RefToOperator     = operator   
        self.maxDelay          = 60                  # maximum number of seconds between connection attempts
    def __del__(self):
        self.RefToOperator.debug( '0 Stopping SocketClient.')
        
    def buildProtocol(self, addr):
        p = ReconnectingClientFactory.buildProtocol(self, addr)
        self.connectedProtocol = p
        return p                                  
    def clientConnectionFailed(self, connector, reason):
        self.RefToOperator.debug('0 Connection failed. Reason:' + str(reason))
        logging.warning('Connection failed. Reason: %s', reason)
        ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)       
    def clientConnectionLost(self, connector, reason):
        self.RefToOperator.debug('0 Lost connection.  Reason:' + str(reason))
        self.connectedProtocol = None
        logging.debug('Connection lost. Reason: %s', reason)
        ReconnectingClientFactory.clientConnectionLost(self, connector, reason)       
        
    def reactOnReceive(self, String):
        self.RefToOperator.debug('2 Received Data from Mothership:' + str(String))
        self.RefToOperator.reactOnReceivedData(String)
       
    def sendMessage(self, Message):
        self.connectedProtocol.SendMessage(Message)
 
I woul'd be glad about any help or clue.
Greets,
Toni
_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to