tags:

views:

3691

answers:

4

Hi all

I would like to write a program that monitors for TCP ports, similar to TcpView, but the thing is, it must fire off events if certain ports are used. The scenario:

License server, and client-program. The license server may use port 1234 to listen and establish multiple connections. The client connects from his pc to the server via port 1234.

When a packet is sent/received on that port, an event must be triggered on the client PC.

Any ideas where to start? (Have googled, and stumbled across old sites with useless info)

Regards,

A: 

It sounds like you will want to use the HTTPListener class on the server side.

http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx

The HTTPListener will bind to a TCP port and listen for any incoming connections. Once a connection is detected it will fire an event which you can handle and do any required processing.

Jon Tackabury
Glancing over the docs, this seems to only listen for HTTP requests, can it handle any protocol?
Neil Aitken
+3  A: 

I think you're looking to set up a simple TCP server, like this:

http://www.switchonthecode.com/tutorials/csharp-tutorial-simple-threaded-tcp-server

Ben Alpert
A: 

This project makes it : sharp pcap or here sharp pcap

lsalamon
A: 

In order to sniff packets, I recommend a great WinPcap wrapper to use in C# or VB.NET (.NET wrapper) called Pcap.Net: http://pcapdotnet.codeplex.com

brickner