On Sat, 12 May 2007 14:44:31 -0700, Sir C4 <Va*******@gmai l.comwrote:
[...]
I'm looking for an event that will fire once a tcp port moves from the
listening status to established status.
You should probably learn more about TCP first.
There's no such thing as a TCP port moving "from listening status to
established status". An entirely new connection, with the "establishe d"
status, is created when an application with a "listening" TCP port accepts
the connection. But the "listening" TCP port remains, and is still
listening for new connections.
I want this to run as a
service so I don't want it to chew up cycles constantly checking for a
specific port to move form listening to established that's why I ask
for an event.
Short of sniffing the network traffic and watching for TCP connections
being created, I'm not aware of any way to do what you want. Not directly
anyway.
One thing you could do is poll the TCP status and check for new
"establishe d" connections on the same port as a "listening" port.
Obviously you wouldn't want to poll too often (maybe once every 5 or 10
seconds), but this would be one way to do it.
The obvious problem with this is that a connection could be closed and
then reopened between the time you've polled, or opened and closed for
that matter. You won't get guaranteed notification of network connection
changes this way, but it might be close enough for your purposes. Depends
on what you're actually doing.
Basically I want to execute some code once the port
moves from listening to established, and then run some clean up code
once it moves from established back to listening.
If you think it might be useful for getting better advice, you might
consider being more specific about the "clean up code". I'm having a hard
time imagining what one process would be able to usefully "clean up" in
response to some other process connecting or disconnecting TCP
connections. There's a small possibility that there's an entirely
different approach to accomplish what you're trying to do, but no one can
offer that information if they don't know what the end goal here is.
Pete