Listen to a port

I need to write an app which would listen to a certain port number, used by another program P (both running on my computer), and log all data passing through this port. My app must not interfere with P, and the only reason I need it for is to see what P is sending/receiving at this port.

I do not even know if it's possible. Any suggestions on how I can do this ?
LVL 1
olegspAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pagladasuCommented:
Take a look at this site. Maybe, it will help you:
http://www.codeguru.com/network/commspy.shtml
0
anoopsCommented:
I guess, you can use CSocket in the client mode of this purpose. See the documentation in MSDN for CSocket
0
kishk91Commented:
btw. the new address of codeguru
is:
http://codeguru.developer.com

the old address is no longer available.

regards
kishk91
0
mattdaimonCommented:
You should use winsock(windows sockets).
You can do it either directly or with the help of some class like CAsyncSocket( better use it than CSocket). You should listen to port(in winsock you can do it by 'bind' function) then write data you reseived to disk and analyze it how you want. I think that there are examples in MSDN or at codeguru.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.