[Twisted-Python] How to get initialize values of function

I have code like that: class class1: def funct1(self, some_args): if a==b:#(the condition doesn't matter) self.funct30("value") enother_val=funct30().__init__ #it doesn't work #i want to have in enother_value="value" - argument from function funct30() def funct30(self, value): # do something # i can't return here a value, because the program work inappropriate Maybe this is a very simple solution, but i have got now any idea. Thanks in advance for answers

hi, i'm working with socket and i need to make two consecutive connection binding the client on the same address. When i try to execute the code i have an error like this: socket.error: (98, 'Address already in use') even if i have correctly closed the socket !?! I use a code like this: v----------------------------------------------------------------------------------------------v def main(self): self.connect(remoteAddress, localAddress) ...do something... self.closeSocket() self.connect(remoteAddress, localAddress) def connect(self, remoteAddress, localAddress): self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.s.bind(localAddress) self.s.connect(remoteAddress) self.connectionMade() def closeSocket(self): self.s.shutdown(2) self.s.close() ^----------------------------------------------------------------------------------------------^ I tried with the twisted api too doing something like: v----------------------------------------------------------------------------------------------v self.reactor.connectTCP(remoteIp, remotePort, ClientFactory(self), 30, (localIp, localPort)) ... self.transport.loseConnection() ... self.reactor.connectTCP(remoteIp, remotePort, ClientFactory(self), 30, (localIp, localPort)) ^----------------------------------------------------------------------------------------------^ but the result is the same. Any suggestions? thanks Luca Gaballo

On Aug 9, 2005, at 12:44 PM, Gaballo Luca wrote:
The kernel prevents you from reusing a local port for a few seconds in order to properly implement some timeout in the TCP spec. You don't really want to bypass this. There is pretty much no reason to ever bind a client tcp socket to a specific port. So, your problem is solved simply by removing the 'bind' call. Or, if you do want to bind to a local IP addr, simply set the local port to 0 so the kernel will autoselect. James

hi, i'm working with socket and i need to make two consecutive connection binding the client on the same address. When i try to execute the code i have an error like this: socket.error: (98, 'Address already in use') even if i have correctly closed the socket !?! I use a code like this: v----------------------------------------------------------------------------------------------v def main(self): self.connect(remoteAddress, localAddress) ...do something... self.closeSocket() self.connect(remoteAddress, localAddress) def connect(self, remoteAddress, localAddress): self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.s.bind(localAddress) self.s.connect(remoteAddress) self.connectionMade() def closeSocket(self): self.s.shutdown(2) self.s.close() ^----------------------------------------------------------------------------------------------^ I tried with the twisted api too doing something like: v----------------------------------------------------------------------------------------------v self.reactor.connectTCP(remoteIp, remotePort, ClientFactory(self), 30, (localIp, localPort)) ... self.transport.loseConnection() ... self.reactor.connectTCP(remoteIp, remotePort, ClientFactory(self), 30, (localIp, localPort)) ^----------------------------------------------------------------------------------------------^ but the result is the same. Any suggestions? thanks Luca Gaballo

Gaballo Luca <luca.gaballo@rd.francetelecom.com> writes:
socket.error: (98, 'Address already in use')
The pure Python TCPServer and UDPServer classes have a class variable "allow_reuse_address". Set to "True" will allow quick re-binding. It needs to be set before any server instances are created. For example I use this bit of code in some non-Twisted XML-RPC server code: from SimpleXMLRPCServer import * SimpleXMLRPCServer.allow_reuse_address = True However, I don't know if your Twisted based server ultimately inherits from one of these classes. -Brett.

hi, i'm working with socket and i need to make two consecutive connection binding the client on the same address. When i try to execute the code i have an error like this: socket.error: (98, 'Address already in use') even if i have correctly closed the socket !?! I use a code like this: v----------------------------------------------------------------------------------------------v def main(self): self.connect(remoteAddress, localAddress) ...do something... self.closeSocket() self.connect(remoteAddress, localAddress) def connect(self, remoteAddress, localAddress): self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.s.bind(localAddress) self.s.connect(remoteAddress) self.connectionMade() def closeSocket(self): self.s.shutdown(2) self.s.close() ^----------------------------------------------------------------------------------------------^ I tried with the twisted api too doing something like: v----------------------------------------------------------------------------------------------v self.reactor.connectTCP(remoteIp, remotePort, ClientFactory(self), 30, (localIp, localPort)) ... self.transport.loseConnection() ... self.reactor.connectTCP(remoteIp, remotePort, ClientFactory(self), 30, (localIp, localPort)) ^----------------------------------------------------------------------------------------------^ but the result is the same. Any suggestions? thanks Luca Gaballo

On Aug 9, 2005, at 12:44 PM, Gaballo Luca wrote:
The kernel prevents you from reusing a local port for a few seconds in order to properly implement some timeout in the TCP spec. You don't really want to bypass this. There is pretty much no reason to ever bind a client tcp socket to a specific port. So, your problem is solved simply by removing the 'bind' call. Or, if you do want to bind to a local IP addr, simply set the local port to 0 so the kernel will autoselect. James

hi, i'm working with socket and i need to make two consecutive connection binding the client on the same address. When i try to execute the code i have an error like this: socket.error: (98, 'Address already in use') even if i have correctly closed the socket !?! I use a code like this: v----------------------------------------------------------------------------------------------v def main(self): self.connect(remoteAddress, localAddress) ...do something... self.closeSocket() self.connect(remoteAddress, localAddress) def connect(self, remoteAddress, localAddress): self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.s.bind(localAddress) self.s.connect(remoteAddress) self.connectionMade() def closeSocket(self): self.s.shutdown(2) self.s.close() ^----------------------------------------------------------------------------------------------^ I tried with the twisted api too doing something like: v----------------------------------------------------------------------------------------------v self.reactor.connectTCP(remoteIp, remotePort, ClientFactory(self), 30, (localIp, localPort)) ... self.transport.loseConnection() ... self.reactor.connectTCP(remoteIp, remotePort, ClientFactory(self), 30, (localIp, localPort)) ^----------------------------------------------------------------------------------------------^ but the result is the same. Any suggestions? thanks Luca Gaballo

Gaballo Luca <luca.gaballo@rd.francetelecom.com> writes:
socket.error: (98, 'Address already in use')
The pure Python TCPServer and UDPServer classes have a class variable "allow_reuse_address". Set to "True" will allow quick re-binding. It needs to be set before any server instances are created. For example I use this bit of code in some non-Twisted XML-RPC server code: from SimpleXMLRPCServer import * SimpleXMLRPCServer.allow_reuse_address = True However, I don't know if your Twisted based server ultimately inherits from one of these classes. -Brett.
participants (5)
-
Brett Viren
-
Gaballo Luca
-
James Y Knight
-
Michał Tyde
-
Stephan Popp