Luke Davis wrote:
I'm looking for an effective way to open and close TCP ports. Can I do
this through Tcpclient? And I know this is a potential security risk, so
what kind of permission must the person running the application possess to
handle it without errors?
Yes, and No, all at the same time. Your question is pretty vague, so it
would help a great deal if you could pin it down a bit better.
Leaving the firewall comments to Nicholas and taking them out of
consideration, opening a port presents no great security risk. Opening a
port that has an application listening on it that is vulnerable to
various attacks presents a security risk.
Semantical discussion aside, you asked about permissions. On Windows,
the permissions that matter in relation to opening ports are whether
you're Administrator/System or not. If you are running as System:
- You can open a listening TCP or UDP socket in the Well-Known port range.
- You can perform raw socket operations (unlikely that you will ever
need this).
This page lists the various port ranges:
http://www.microsoft.com/technet/com...uy/cg1205.mspx
As for what to use, assuming still that this is an incoming "server"
type connection you want to open, then TcpListener is probably what
you're looking for. If you want to connect out to another box, TcpClient
should be correct.
Elaborating more on what you are trying to do will definitely get you
clearer responses though.
Chris.