[Twisted-Python] Is it possible to write a tcp app which behaves like both client and server?
![](https://secure.gravatar.com/avatar/2b920f5b50704962d9897786154f18f4.jpg?s=120&d=mm&r=g)
Hi all! Sorry for my poor english, I'll try to express myself clearly :p I need to implement something like this: * it listens on a port 12345 for only one incoming connection if there is currently no connection * it can also connect to other host from that port (12345) if there is currently no connection Or: Could I write a server which can connect (from the port it's listening on) to another known server? Could these be done with twisted? Any infomatin would be warmly welcome, big thanks! - Eric
![](https://secure.gravatar.com/avatar/d7875f8cfd8ba9262bfff2bf6f6f9b35.jpg?s=120&d=mm&r=g)
On Tue, 2005-06-28 at 20:36 +0800, Eric Hsu wrote:
Or: Could I write a server which can connect (from the port it's listening on) to another known server?
You can't have (in TCP) something that is both server and client on same port. You can either connect while bound to a port or you can listen to a port. It is possible with UDP, however. However: there is no reason why TCP clients should connect *from* a specific port, it doesn't give you anything. So why bother? Just have servers listen on a well known port.
![](https://secure.gravatar.com/avatar/d7875f8cfd8ba9262bfff2bf6f6f9b35.jpg?s=120&d=mm&r=g)
On Tue, 2005-06-28 at 20:36 +0800, Eric Hsu wrote:
Or: Could I write a server which can connect (from the port it's listening on) to another known server?
You can't have (in TCP) something that is both server and client on same port. You can either connect while bound to a port or you can listen to a port. It is possible with UDP, however. However: there is no reason why TCP clients should connect *from* a specific port, it doesn't give you anything. So why bother? Just have servers listen on a well known port.
participants (2)
-
Eric Hsu
-
Itamar Shtull-Trauring