Doors Page of Programming |
Welcome to my pages of simplistic Programming |
|
I use Freepascal mostly I can use C & C++ but try not to FPC MINGW CYGWIN The files below are works in progress. The first includes everything. The second uses a unit. TcpRead Tcpread2 NntpRead NntpRead2 |
This guide is intended for those who want to know the low level details. It is not intended for for those who depend on abstraction. Though I can and do use abstraction, I do not like it when it is not needed. Most of the programming stuff I have come across over the years demonstrates how to use libraries, a type of abstraction. That is to say the guides stress that you the programmer can ignore how big or exactly what a variable really is. This is great once you know what it is, however if you are like me, and admitedly not a lot of people are, then you need to see the details at least once, no shorthand, no self referential documentation, no shorthand, no shortcuts, no leet speak to keep out the uncool kids who don't speak that particular dialect. I am beginning my series on the simplistic stuff of programming with how to program using sockets. Sockets are used for network programming. You will find lots of words to describe sockets, yet those words won't actually tell you what sockets really are. You used a socket to get here though, assuming you are reading this on a web browser that is. If you have ever played with a terminal (Especially in Linux), you were using a form of a socket. (Even the old BBS's from years ago are loosely related.) The closest description I have found of a socket is a displayless terminal you send a text request to and get binary files in return. In it's simplest form a socket is a means of sending and recieving files over a network. Yet the socket interface itself is network agnostic, that is it is not tied to any particular protocol or interface or hardware. A socket can be used over anything that supports two way communication. So how you ask, do I use one? It turns out using sockets is both easy and hard. The blessing and the curse of sockets is that they are independant of the hardware or connection type you are using. They are what is called, logical. That is to say they are a logical conection, I know, big word, yet if they were so logical how come there are so many pages dedicated to using and answering questions from comfused people? Because in this case logical means that no matter how the information is carried it looks the same to you, the only difference you see is speed, in computer speak that is logical, it always looks the same to yuor program, whether it makes sense to you the human or not is beside the point. This also gives your programs flexibility, lots of flexibility. As long as your program uses sockets, the socket interface takes the request from your program and changes it into whatever form is needed for the network you have. So a request for a web page, like the one here, a standard request, is taken by the socket interface (API - Application Programming Interface) then mapped (it changes the format of your request) into whatever format makes sense for however your computer is networked. The nice part for you the user and for the programmers is that no matter what operating system or computer type you are on, as long as it has sockets, they can simply recompile their program and run it since all socket interfaces are the same. So now that I have boiled page after page of stuff down to a few paragraphs, what exactly is a socket anyway? A socket is how your program tells the operating system it wants to talk to someone somewhere else. It can be accross the room, the building or the planet, the request is the same. You tell the OS you want a SOCKET. Once you have it, you tell it where you want it to CONNECT to, what HOST has the file. Once it is connected you SEND your request for a file through the socket. After your request is sent, you RECV the file. If you need more files, you SEND more requests and REVC more files. Once you are done you CLOSE the SOCKET and work with the files. This then is the heart of all socket programming. The first example file (tpcread.pas) in the left column reads the index.htm file from my domain. The second example file (tcpread2.pas) in the left column does the same only it uses a unit called doorsock I am developing as I write this. A horrid pun but it is the Doors Socket Interface.(Antispam in effect - Read address carefully) I shall add a break down shortly. |
|