What ports do you think are opened, sending and receiving data? On top of that (as if the connection wasn't slow enough already), you're trying to send and receive email. Of course, if instead you want to listen in on messages sent to and from service ports, you can do that too.Īre you connected to the Internet now? Let's say you are, and you have Internet Explorer or some other web page service running, as well as AOL or some other chat program. Typically though, if you wish to use a port that has no specific assigned service, any port from 1,000 to 6,535 should be just fine. There are many more ports used for specific purposes that are not shown here. A few commonly used ports are listed below with their corresponding services: Port Beyond these ports, there are quite a large number of other ports that can be used for anything and everything: over 6,000, actually. A few of these ports have been set aside to serve a specific purpose. In order for the threads to be attached to each computer, however, there must be a receiving object that attaches to the threads, and these are called sockets.Ī socket can be opened on any "port" which is simply a unique number to distinguish it from other threads, because more than just one connection can be made on the same computer. In case I've lost you with all that proper terminology, you might think of a thread as an actual, physical, sewing-type thread stretched from one computer to the other, as the common analogy goes. A "thread" is a symbolic name for a connection between your computer and a remote computer, and a thread is connected to a socket. In an actual mechanical socket, you may recall that it is the female, or "receiving" end of a connection. What the Heck are Threads, Ports, and Sockets?Īctually, we can use the word-picture presented to us by the name "socket" in a similar fashion to illustrate what they are and how they work.
If this is not possible, use LoadLibrary() to load ws2_32.dll at runtime, or some similar method.Īll the code in this article was written and tested using "Bloodshed Dev-C++ 4.9.8.0" but generally, it should work with any compiler with minimal modifications. Thus, I present this tutorial in the hopes that it alone will be sufficient information to begin programming.īefore we begin, you will need to include winsock.h and link libws2_32.a to your project in order to use the API that are necessary for TCP/IP. My goal is to collect all the necessary data in one place right here, so the reader doesn't have to recollect all the data over the Internet. Thankfully, after many hours of searching various web pages on the Internet, I was able to collect all the bits and pieces, and finally compile my first telnet program in C++. Now that I have long since switched to the more powerful C++, I rapidly found that the labor I had expended to code sockets in VB was nothing compared to what awaited! That was a long time ago now, and it was quite a challenge for me to program my first application that could communicate with other computers over the Internet – even though my first introduction to sockets was through Visual Basic a high-level and very user-friendly programming language. I still remember the hassle that I went through trying to find a proper tutorial that didn't leave me hanging with many questions after I started programming with them myself.
There really is not a lot of material on this subject (I believe) that explains the use of Windows sockets sufficiently enough for a beginner to understand and begin to program them.