Topic : Socket Programming
Author : Vijay Mukhi
Page : 1 Next >>
Go to page :

Socket Programming
Getting back to the basis

All this while we've been talking about creating ActiveX Objects and Java applets and other Internet related stuff. Even though we talked long and hard about transferring files via the Internet, we haven't really tackled the basic issues of HOW the files are transferred. We've pointed out the various shortcomings of different languages and browsers and yet we've never told you how they worked. Infact, come to think of it, we've really left you in the dark about how the Internet really operates.

Well, it's confession time, we didn't know either !! Infact, if we hadn't worked for two hard weeks cracking code and reading piles of books, we still wouldn't know. So, here it is, the fruits of our labor, a complete tutorial, with source code and explanations about nearly every aspect of the 'net from TCP/IP and DNS Servers, to Traceroute Ping. So read on and broaden your horizons !!

A Prelude.....

I personally could never have predicted that the net would grow at such a pace that one day, commercials would give web site addresses right at the end. Even the man on the street knows that a programming by the name of Java exists. The Internet is no longer a geek hangout, it's being slowly integrated into the global and International communications mainstream. The Web has grown so fast and the software has become so complicated that in the last six months, I've had to totally revamp my entire knowledge base.

The problem with the Internet is that although everyone knows about it, it is not a technology that most programmers fully understand. Unlike the all the computer languages use , there is no central command or controlling body. Also, the net assures relative anonymity. No one can know whether your working on a UNIX workstation, a Mac, a Pentium or a 286 with 1 MB RAM and a 40 MB hard disk !! All these rambling debates about whether UNIX is good or bad or whether the Mac OS is better that Windows 95 are meaningless. This perhaps is the real reason behind the feeling of equality in cyberspace.

While learning C under DOS for the first time ( a long long time ago, in a galaxy far far away !), I realized that no matter how close the language may be to the computer, for me, it wasn't close enough. So, after my C course, I went out and learnt assembly. I personally think that the most productive time in my programming career was when I learnt to write a virus, because after that, I knew DOS inside out. I was completely comfortable with it. I could say "DOS, your mine !" with a certain amount of self confidence. I can't however, say that about Windows95, because I don't know what the hell is going on under the hood. ( In DOS, there was no hood !! ) The same goes for the 'net, I really didn't know what happened when I said

In India, it is below my dignity to wash, tune up or even fill up my own car ( AH ! the pleasures of a large work force !! ). It is the driver job, not mine. Yet if I took care of my machine myself, I'd know more about it, I'd know what makes it run. This is the reason perhaps that Americans are better drivers!!

What I'm trying to say is that we can't understand something as amorphous as the Internet until we get our hands dirty; unless we write our own code. Now, in India, I am quite a well known public figure. So I'm often called upon to give these great bombastic lectures about the Internet. I stand in front of a crowd full of eager listeners and I shoot my mouth off about the 'net and until a week ago, I would feel like a fake, because I really didn't know what I was talking about ! But now, that I've written my own programs, blundered through my own code, I can truthfully say, " Internet, your mine !!". Being a nice guy I like to share and share alike, so I'm going to try and teach you how to write your own Internet software suite. We'll do the basics of WinSock programming with TCP/IP and UDP.

Now there are already books available that teach you how to write an email client and other Internet software, but they usually end up confusing people because around 95 % of the code they list deals with the User Interface. Only 5 % of the code deals with the Internet. Now at the moment, I really don't want to create a marketable product, that can come later. What I want to do is understand the Internet related code and this is precisely the code we're going to teach you.

Now, if you're going to learn from us, you'll have to follow our rules. First write the code the way we want you to (No blinking, no breathing, no drooling and you have to type with the big toe on your left foot) and then add your own embellishments later. In a break from tradition we're going to provide you with finished polished code, along with the rough and ready stuff we use to help you learn ( Learning Code we call it ). This in itself should tell you how seriously we taking this and how important we think it is.

The reason we believe every programmer should learn this technology is because we think that the Internet is the future. From now on, we have to stop thinking of machines as islands, complete in themselves, but as one continuously connected nation. Even the humble wordprocessor needs to be Internet ready, able to send and receive email and faxes. Accounting packages should be able to log onto a specified server to collect the latest information about a company or product. With all these advances, EVERYONE needs to learn how to program for the 'net. After all, wouldn't you understand the intricacies of the web better if you could write a program that connects to a site and then tells you the exact route the TCP/IP packets will take to reach the said site ?

Now the code given here is in C/C++, but making the code Internet ready is a breeze. You can convert your code into an ActiveX Object ( Check out our tutorial ) or into a Java applet (we have a tutorial on this too ...) or into a Netscape plugin ( ditto). We have a Traceroute program as an ActiveX Object which is put up on our site. So when you visit our site, you can click in a certain window and type in the name of the site you want to trace and see the route the packets take from our server to the specified site.

To convert your code into an ActiveX Object, which can be used from under any language that's OLE compliant, all you have to do is add a little more code, a little more complexity. Once you've converted your program, every server on the Internet can have it. The finished programs at the end have all kinds of error checks and also a decent user interface, but if we were to try and teach using that code, you'd spend sleepless nights trying to wean the chaff from the real code. So, we be teaching using rougher and more unpolished code , which you're probably used to if you've been visiting our site regularly. Infact, along with the ActiveX Objects, we'll give you Java applets and Netscape Plugins. Maybe even some code using LiveConnect or OLE Automation !

A Request...

The good people from Microsoft often send us complementary email. Now that doesn't mean that Bill Gates sends us mail ( after all, I said the GOOD people from Microsoft !! ), it's the people behind Active Animation or ActiveX who write to us. And believe me, I prefer their mails to any correspondence Gates may want to send (except for large generous cheques!!). Unfortunately, their high command still hasn't noticed us, so if you like this site, do us a favor and petition Microsoft to put up the name of our site on their " To Visit " list ( Mailto : XXXXX ). Oh, and by the way, If you intend to use our programs, please place an Easter egg in them so that when the user clicks his mouse on the upper left-hand corner of the screen, jumps up and down on his chair shouting " Bonga Boola Boola !! " , kisses his toes ( in turn, from right to left ) and it's my birthday ( 29th Feb. ), you'll tell him where you got the code from.

Originality - The art of concealing ones sources ....

A lot of the code here has been adapted from samples we found on

Page : 1 Next >>