Listen to data on a C # TCP port

I would like to write a program that monitors TCP ports similar to TcpView, but the fact is that it should fire events if certain ports are used. Scenario:

License server and client program. The license server can use port 1234 to listen and establish multiple connections. The client connects from its computer to the server through port 1234.

When a packet is sent / received on this port, an event should be fired on the client PC.

Any ideas where to start? (Go goled, and stumbled upon old sites with useless information)

Hello,

+4
source share
3 answers

I think you want to configure a simple TCP server, for example:

https://web.archive.org/web/20090720052829/http://www.switchonthecode.com/tutorials/csharp-tutorial-simple-threaded-tcp-server (link archive.org, the source site does not work)

It uses the TcpListener class in System.Net.Sockets from the standard library:

https://msdn.microsoft.com/en-us/library/system.net.sockets.tcplistener(v=vs.110).aspx

+7
source

It looks like you will want to use the server-side HTTPListener class.

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

The HTTPListener will bind to the TCP port and listen for any incoming connections. Once a connection is found, it will fire an event that you can process and perform any necessary processing.

+2
source

To sniff packages, I recommend the excellent WinPcap shell for use in C # or VB.NET (.NET shell) called Pcap.Net: http://pcapdotnet.codeplex.com

0
source

All Articles