TCP/IP stands for – Transmission Control Protocol / Internet Protocol. This protocol is widely used throughout the world and is a standard way of communication across the Internet. With the way things are going, Internet enabled", I thought I’d try and explain TCP/IP by way of examples and projects.
I personally am totally in love with this technology. It is VERY powerful and has opened up the whole world to me (literally). Today, I understand a lot of what is going on and how it’s done, primarily because I now understand TCP/IP. In the short time that I’ve been playing around with TCP/IP, I have done some really wonderful things with it. Let’s get down to it….
For this protocol to work there has to be a client and a server socket. A socket is referred to as an end point. An application that contains a client socket is called a client while an application that contains a server socket is called a server. The client establishes a connection with the server and once this connection is established data can be transferred from the client to the server or server to client (Also known as full duplex) over the same connection. For a connection to be established the client needs to know the IP address and a port number (also known as a SOCKET).
TCP/IP is a connection-oriented protocol. Data is transferred from one socket to the other in the form of bytes. The TCP/IP protocol guarantees that all data sent will be received (as long as a connection is maintained). It does not guarantee however that the data will be received in the way it was sent. But it does guarantee that the data will be received in the order in which it was sent.
Let me explain the above a bit more with some example. Let’s say we have a client application and a server application that have established a connection. Let’s say that we send the string "Borland" and then "Delphi" from the client to the server. Just because you first sent the string "Borland" and later sent the string "Delphi", does not mean that the server gets it as two packets. The server will receive all the data, but not as you sent it. It could receive it all in one packet (BorlandDelphi) or in any combination. Even one byte at a time! Only the order is guaranteed and what was sent will be received. The time it takes and the way it is received all depends on the network speed and traffic.
Seeing this possibility, one generally has to devise ones own protocol "on top of" the TCP/IP protocol. The simplest thing one could do is, transmit every string with an ending carriage return and line feed. Then on the server side, you break up the bytes received by scanning for a carriage return and line feed combination. So you will then know that the string "Borland" was sent and then the string "Delphi" was sent. You will always define your own "protocol" when working with TCP/IP for this reason. Some protocols that have already been defined are HTTP, SMTP, POP, FTP etc. These are standards. An HTTP Client (Browser) knows how to "talk" to an HTTP server (web server) since the protocol is a standard. Therefore you can use any browser with any web server.
Lets look at a real example of this. To try this example, you will need:
- A connection to the Internet.
- The IP address or host name of your POP3 server.
- Your user name /account for this server.
- Your password for the account.
- A telnet client. (Win95/98/NT has a telnet client).
Lets say, my email address is shivk@erols.com
Generally, the POP3 server name is - pop.erols.com. (or pop3.erols.com or even erols.com)
The port POP3 uses is 110. (its a standard)
The user name is shivk
Let’s say my password is delphi.
I’ll use the telnet client that comes with win95/98/NT for this example.
- Choose Start | Run from the task bar and type – telnet and then click OK.
- From the telnet client’s Connect menu choose – Remote System.
- Type in your POP3 server name in the Host Name field. (pop.erols.com)
- Type in 110 in the port field.
- Click OK.
- The telnet client will connect to your POP3 server and you should see a response from the server. The POP3 protocol says that a POP3 server should respond with a " OK". What you see after the first 4 characters is dependent on the server application.
- In the telnet screen type the words – user shivk and press the Enter key.(use your account name instead of – shivk).
- Again, if you typed it correctly, you should see that the server responds with a " OK".
- Next type – pass delphi and press the Enter key (use your password instead of – delphi).
- The server should respond with a " OK" once again.
- You have now logged into you email server directly. This is what your email client does for you.
- Next type in – list and press the Enter key..
- The server should respond with a " OK" and the number of messages and their sizes.
- If you have any messages, type in – retr 1 and press the Enter key (1 is the first message).
- You should see the first email that the server has waiting for you. This email will contain the full header as well as the message itself.
- If you want to Delete this message, you would type Dele 1. I suggest you DON'T do this !
There are other commands a POP3 server understands, such as DELE etc. What you need to understand here is that all of the above is a protocol. Even pressing the Enter key after each command is a part of the protocol. A way of communication established for a POP3 server. Your email client knows of this protocol and is doing what you just did, to retrieve your email from your email server. It’s a more user friendly way to doing it. The POP3 server responds with a "–ERR" if you type in a command it does not understand or if your commands are not in the right sequence.
As another example, I have built a VERY simple TCP/IP server that is running on my PC. I’ve established a certain protocol that you need to use to communicate with it. Use the same telnet client for this.
The host name is www.matlus.com
The port is 3232.
Basically, it will respond with whatever you send it, along with a " OK" and your IP address and the date and time on my PC at the time of responding.
A "command" it understands is – About. See what happens when you type in the word – about.
This server is also capable of sending back information from a database. The TQuery component is connected to the DBDEMOS Alias. To fire a query on the server the command is SQL: followed by the SQL statement you want it to execute. So if you wanted to see all records of the table, you type:
SQL: SELECT * FROM CUSTOMER
Any valid SQL statement is allowed. You will also notice that the first line returned is the fields names. And also, that each field is delimited by a special character #0183 and that each line is delimited with #1086. I’ve chosen these just because I like them ! This is my Protocol
This will come in handy when we build the client application for this server (rather than use telnet).
If you want to join a list server dedicated to this tutorial, have a look at my List Server link.
If you liked this article and would like to see more, please let me know.email me