Here's a good example using C#. It does a lot more than what you ask for, but I'm sure you can zoom in on the relevant bits...
http://msdn.microsoft.com/en-us/magazine/cc163648.aspx[
^]
Choosing the port is up to you. Don't use anything below 1023, because they're pre-assigned to services. You should make your port configurable, because someone else may have chosen the same port, and you'll run into a conflict.
Best practice is to get something above 6000.