[Twisted-Python] Socket bind and re-bind problems

Gaballo Luca luca.gaballo at rd.francetelecom.com
Tue Aug 9 12:44:59 EDT 2005


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

 
  




More information about the Twisted-Python mailing list