TCP/IP Emulator - School of Computing

hollowtabernacleΔίκτυα και Επικοινωνίες

26 Οκτ 2013 (πριν από 3 χρόνια και 11 μήνες)

64 εμφανίσεις

1



DIAGNOSTIC TOOL FOR HIGHER LEVEL PROTOCOL
TESTING ON A TCP/IP BASED NETWORK




FAISAL ASLAM











submitted in partial fulfilment of the requirements of
Napier University for the degree of
Bachelor of Engineering with Honours in Software
Engineering



School of Computing
August 2001

2
Abstract


The aim of this project is to design and implement a system, which will test session layer
protocols. Protocols are used for communicating between software packages.
The software will contain a Client and Server architecture to test the protocols over a network.
The project will use Transmission Control Protocol/Internet Protocol (TCP/IP) protocols, such as
File Transfer Protocol (FTP), Simple Mail Transfer Protocol (SMTP), Hypertext Transfer
Protocol and the terminal emulation protocol, Telnet.

This report will test the connection and protocols using a Client and Server architecture.
This report provides a step-by-step explanation of TCP/IP theory, design, test and
implementation. Instead of just describing the protocols and what they do, a diagnostic tool will
be developed to watch the protocols in action. This project also provides a look into the
implementation of the protocols, without having to go through thousands of lines of source code.

Many people might consider this tool to be used for diagnosing network problems, but it is also a
powerful tool for understanding how the network protocols operate.

The test system will use a client/server architecture, where the device on-test will act as the
client, and the other program will act as a server. Each client will make requests for a given
protocol to the server, which will respond with a basic set of responses.
3
Contents

1 Introduction..............................................................................................................................6
1.1 Aims and Objectives............................................................................................................6
1.2 Report Layout........................................................................................................................6
1.3 Background..........................................................................................................................7
2 Theory......................................................................................................................................8
2.1 Introduction..........................................................................................................................8
2.1.1 Networking/OSI..................................................................................................................8
2.2.1 Networking History.....................................................................................................8
2.2 The OSI model.......................................................................................................................9
2.3 TCP/IP.................................................................................................................................10
2.3.1 TCP...............................................................................................................................10
2.3.2 TCP/IP Applications...............................................................................................11
2.3.3 Layers.......................................................................................................................11
2.4 IP..........................................................................................................................................12
2.4.1 IP Addresses and Host Names...................................................................................12
2.5 Ports...................................................................................................................................12
2.6 Protocols..............................................................................................................................13
2.6.1 SMTP (Simple Mail Transfer Protocol)....................................................................13
2.6.2 Telnet.........................................................................................................................14
2.6.3 File Transfer Protocol (FTP).....................................................................................14
2.6.4 Hypertext Transfer Protocol (HTTP).........................................................................15
2.7 Object Oriented Design.......................................................................................................16
2.8 Visual Basic WinSock.........................................................................................................16
Connect Event........................................................................................................................16
Close Event............................................................................................................................16
DataArrival event...................................................................................................................16
Bind method...........................................................................................................................16
Listen method........................................................................................................................17
2.8 Conclusion.........................................................................................................................17
3 Design....................................................................................................................................18
3.1 Introduction........................................................................................................................18
3.1.1 Specification..................................................................................................................18
3.1.2 Purpose......................................................................................................................18
3.1.2 Hardware....................................................................................................................18
3.1.3 Quality Goals.............................................................................................................18
3.1.4 Portability..................................................................................................................18
3.1.5 Efficiency...................................................................................................................18
3.1.6 Reliability..................................................................................................................19
3.1.7 Maintainability...........................................................................................................19
3.1.8 Usability.....................................................................................................................19
3.1.9 Functionality..............................................................................................................19
3.2 Project Requirements...........................................................................................................19
3.2.1 Project Specific Requirements...................................................................................19
3.2.2 Specific areas of exclusions from the project............................................................19
Client/Server Design..................................................................................................................19
3.2.4 Client/Server.................................................................................................................19
3.3 Client/Server Design......................................................................................................20
4
3.3.1Designing the Client......................................................................................................20
Server Design.............................................................................................................................21
3.4 Designing the Server......................................................................................................22
3.4 Conclusion.........................................................................................................................22
4 Testing...................................................................................................................................24
4.1 Introduction........................................................................................................................24
4.2 Test Plan..............................................................................................................................24
Problems................................................................................................................................25
Initialisation...........................................................................................................................25
Read codes from servers........................................................................................................25
4.3 Conclusion...........................................................................................................................25
5 Implementation......................................................................................................................26
5.1 Introduction........................................................................................................................26
5.2 FTP Implementation............................................................................................................26
5.3 SMTP Implementation.......................................................................................................27
5.4 TCP Implementation..........................................................................................................29
5.6 Conclusion.........................................................................................................................30
6 Conclusion.............................................................................................................................31
Appendix 1.....................................................................................................................................32
Documentation and Screen Shots..................................................................................................32
Appendix 2.....................................................................................................................................33
RFC’s.............................................................................................................................................33
Appendix 3.....................................................................................................................................34
Source Code...................................................................................................................................34
References......................................................................................................................................50
Bibliography..................................................................................................................................51
5
Acknowledgements


I would like to thank Dr. W Buchanan my project supervisor for all the support and
encouragement he gave to this project and also of the subject provided and the great interest and
purpose of it.
6
1 Introduction



1.1 Aims and Objectives
The goal of this project is to implement and design a system, which will test session layer
protocols. The aims are to design and implement some of the test session layer protocols such as
SMTP, Telnet, FTP and HTTP. This will be achieved by researching RFC documents such as
RFC822. There will also be a need to implement a Client/Server architecture using TCP/IP. The
project is split into these main areas:

Research
Defining each of the TCP/IP protocols from RFC documents, such as RFC821 which defines the
SMTP protocol (e-mail), RFC2068 (HTTP), and so on.

Set-up of a client/server program
This will set-up a basic text-based connection between the client and the server, and will test the
link over a network.

Implementation of a basic set of protocols
This will be the investigation of the implementation into one or more of the TCP/IP.

Full design
This will use the research and implementation parts to develop the design for a full system.

Prototype (partial implementation)
This will take part of the full design and implement it as a partial implementation

Project write-up
Defines the main objectives of the project, cover the theory of TCP/IP and show the
implementation of the protocols, a full design and outline the developed prototype.
1.2 Report Layout
The report is split into the five following chapters, and will be laid out as follows.

 Chapter 2 describes the theory of TCP/IP and Networking. The OSI model will be discussed
in detail. This will provide a clearer understanding of what is required from the
implementation of the protocols. This will also show the background on how the software
will operate. Session Layer protocols will also be discussed as will Object Oriented Design
and the Visual Basic Winsock. This whole chapter will give a background to the
fundamentals of Networking. Defining each of the TCP/IP protocols from RFC documents,
such as RFC821, which defines the SMTP protocol (e-mail), RFC2068 (HTTP), and so on
will also be covered.
7
 Chapter 3 is concerned with the design side of the project. It will give an insight into the
Client/Server Architecture and also the investigation into the Session Layer. Issues such as
software design and architectures will be covered. This will use the research and
implementation parts to develop the design for a full system. This will set-up a basic text-
based connection between the client and the server, and will test the link over a network.
 Chapter 4 will illustrate the Testing. It will show testing on Protocols, which have been
implemented.
 Chapter 5 discusses the implementation of the design. This looks into the various
implemented protocols and Visual Basic. It will show the Implementation of the various
protocols and the errors encountered.
 Chapter 6 is the summary of the conclusions reached in the project.
1.3 Background
TCP/IP (Transmission Control Protocol/Internet Control Protocol) has become a phenomenally
popular network protocol. Today most networks are TCP/IP based. The growth of the Internet
has helped push TCP/IP to the forefront of network protocols.

With the explosive growth of the World Wide Web, every computer now needs to understand
TCP/IP in order to talk to an Internet service provider. TCP/IP is one of the most stable network
protocols available. The start of the project involved research into each of the TCP/IP protocols
from the RFC documents, such as RFC821 which defines the SMTP protocol (email), RFC2068
(HTTP), and so on. This involved a lot of reading. Also to find a way to create a Client and a
Server. The Client/Server also had to connect to a Server like the Department of Computer
Studies of Napier University, and find the different protocols to communicate with it. Visual
Basic 6 was chosen to make the program because the manipulation of the ports is quite easy in
this language.
8
2 Theory
2.1 Introduction
Today nearly all computers in companies are networked together. This allows an effective way
of communication among the workforce. Email and the Internet are the two most popular
network systems. People can communicate instantly across the world in real time. Everything
from printers to disks can be shared, regardless of its geographical location.

For a network to operate effectively, the computers must speak the same language. This is where
the network protocols come in. These are basically the set of rules that allow to computers or
many more to communicate with each other. One of the most important protocol is called the
Transmission Control Protocol TCP/IP, which is the most standard protocol, which computers
use to connect. It allows access to the Internet and a new world of communication. TCP/IP has
been the most successful communications protocol ever built. Evidence of this is found on the
Internet, as this is the largest open network ever built. It allows all computers regardless of size,
or operating systems to communicate with each other.

This section covers the basics of networking and the OSI model. It also covers TCP/IP and the
session layer protocols. It will describe the theory of TCP/IP and Networking. The OSI model
will be discussed in detail. This will provide a clearer understanding of what is required from the
implementation of the protocols. Session Layer protocols will also be discussed as will Object
Oriented Design and the Visual Basic Winsock. This whole chapter will give a background to the
fundamentals of Networking. Defining each of the TCP/IP protocols from RFC documents, such
as RFC821, which defines the SMTP protocol (e-mail), RFC2068 (HTTP), and so on will be
covered.

2.1.1 Networking/OSI
2.2.1 Networking History
The Internet was specifically designed to facilitate defence research, and to enable the U.S.
Government to continue communications despite the potentially devastating effects of a nuclear
attack. TCP/IP was developed for this purpose. It all started up with the ARPANET (The
Advanced Research Projects Agency) which at the time was looking for ways to improve
communications. The first protocol developed was called the Network Control Protocol (NCP),
but as network traffic got larger NCP was unable to cope. After the birth of ARPANET, Vinton
Cerf and Robert Kahn invented the Transmission Control Protocol (TCP) which replaced the
NCP. The result was the Internet being born [1].

Today the Internet is no longer just used for Military or academic research. Everyone on the
Internet can shop and bank online. The various uses of the Internet are endless.

In 1969 the ARPANET started with four nodes and grew to just under 600 before it was split in
1983. According to an Internet Growth survey, the Internet had nearly 30 million reachable hosts
9
by January 1998. The Internet is growing at a rate of about a new network attachment every half-
hour, interconnecting more than 200,000 networks [2].

2.2 The OSI model
In today’s electronics and computers, there are a lot of problems with compatibility and
interconnection. This includes connecting computers together, which are located at various
points around the world. The International Standards Organisation (ISO) built the OSI model,
which would allow:

 Any kind of computer system, regardless of the manufacturer to interconnect.
 Any type of software and hardware would be compatible.
 This model would be like a rule and regulation for the entire world.

There are seven layers in this OSI model. Data is passed from the top layer (the application
layer) by the sender to the bottom layer (the physical layer) and then back up to the top layer by
the recipient. Each layer can communicate with the preceding layers which allows data flow
amongst the layers.

The application layer receives data from an application and then adds data, which recipient’s
application layer will then receive. The data that is added is passed on to the next layer, which is
called the presentation layer. Here also data is added until you eventually get to the physical
layer. The physical layer has to transmit the data to the recipient. The data which is sent by the
network or the transport layer is called a data packet.

Below are the characteristics of each layer:

1. Physical Layer, states the electrical functions. This is the bottom layer. This layer is
responsible for the transmission of the bit stream. It accepts these frames of data from the
Data Link layer. It deals with all the signals like voltage levels, connecters and cabling
etc. The Physical Layer only sees 1s and 0s. The Physical Layer is also responsible for
the reception of incoming data streams, one bit at a time.

2. Data Link Layer, this is the second layer of the OSI Model. Like all the other layers this
layer too has two sets of responsibilities. These are to transmit and to receive. It ensures
that all data is received in a reliable fashion. Successful delivery means that the frame
reaches its intended destination intact. It achieves this by adding additional bits to
illustrate the start and the finish of the data frame. The Data Link Layer is responsible for
detecting and correcting any errors.

3. Network Layer, is responsible for establishing the route to be used between the host and
destination computers. It routes all data frames through the network. In TCP/IP the IP is
directly involved with this layer.

4. Transport Layer, this layer provides a service very similar to the Data Link Layer as it
also is responsible for the see through of the transmissions. It allows multiple
transmissions from one computer. The TCP is directly involved with this layer.

10
5. Session Layer, this layer likely unused most of the time. The function of this layer is to
manage the flow of communications during a connection between two computer systems.
This flow of communications is known as a session. It ensures that one request is
completed before a new one is taken on. A protocol which is typically related to this layer
in many ways, is Telnet.

6. Presentation Layer, is responsible for managing the way that data is encoded. If systems
use different standards, this layer is responsible for providing the translation between
these systems. It can also provide security encryption and decryption services.

7. Application Layer, this is the very top layer of the OSI model. It provides the network
services to application programs. This can be like FTP and SMTP.

2.3 TCP/IP
Transmission Control Protocol/Internet Protocol (TCP/IP) is everywhere. It can be at any place
at any time. It’s a set of protocols which allow anyone with a computer to communicate with
another. Both TCP and IP are two separate protocols that work together and distribute data
packets reliably over the Internet. They both use special headers that define each packets content.
TCP makes itself busy by making connections to remote hosts. IP deals with the addressing so
that messages are delivered to where they are intended for. The Internet uses TCP/IP to transfer
data.

2.3.1 TCP
Transmission Control Protocol (TCP) is a protocol which provides a reliable stream delivery and
connection to applications. TCP is the transport layer in the OSI model. TCP establishes a
connection-oriented session between two or more hosts. It can also provide multiple data streams
as well as flow and error control.

TCP provides many important functions in a communications session. It can be thought of the
relation between the multiple applications and the network. These are its main functions:

 Multiplexing data from multiple applications to and from networks.
 Testing received data
 Resequencing application data that may have arrived in the wrong order.
 Acknowledging successful receipt of transmitted data.
 Flow control
 Timing functions
 Coordinating the retransmissions of data that was damaged or lost in transit.

These are the parts of the TCP header:

11
 Source Port. This is the numerical value indicating the source port.
 Destination Port. This is the numerical value indicating the destination port.
 Sequence Number. This is the sequence number of the first data octet in any given segment.
 Acknowledgment Number (ACK). When the ACK bit is set, this field contains the next
sequence number that the sender of the segment is expecting to receive.
 Data Offset. This is the numerical value that indicates where the data begins, implying the
end of the header by offset.
 Reserved. Reserved is not used.
 Control Bits. The control bits are: U(URG), A(ACK), P(PSH), R(RST), S(SYN), F(FIN)
 Window. This indicates the number of octets the sender is willing to take. This starts with
the packet in the ACK field.
 Urgent (URG) Pointer. This shows the value of the URG pointer in the form of a positive
offset of the sequence number from the octet that follows the URG data.

2.3.2 TCP/IP Applications
The TCP/IP Application Layer protocols support the applications and utilities that are the
Internet. Commonly used protocols are as follows:

 Telnet: Short for Telecommunication Network, a virtual terminal protocol allowing a user
logged on to one TCP/IP host to access other hosts on the network RFC 854 [5].
 FTP: The File Transfer Protocol allows a user to transfer files between local and remote
host computers RFC 959 [6].
 SMTP: The Simple Mail Transfer Protocol is the standard protocol for the exchange of
electronic mail over the Internet RFC 821. SMTP is used between e-mail servers on the
Internet or to allow an e-mail client to send mail to a server. RFC 822 specifically describes
the mail message body format, and RFCs 1521 and 1522 describe MIME (Multipurpose
Internet Mail Extensions) [8].
 HTTP: The Hypertext Transfer Protocol is the basis for exchange of information over the
World Wide Web (WWW). Various versions of HTTP are in use over the Internet, with
HTTP version 1.0 RFC 1945 being the most current. WWW pages are written in the
Hypertext Markup Language (HTML), an ASCII-based, platform-independent formatting
language RFC 1866 [9].

2.3.3 Layers
Protocols are usually developed in layers, each layer being responsible for a different level of the
communications. TCP/IP is a variety of protocols at different layers. There are four layers of the
TCP/IP protocol suite.

 The Link Layer. This layer is also known as the data-link layer or network interface layer.
This includes the device driver in the operating system and also the network interface card in
the computer. This layer handles all the hardware details.
 The Network Layer. This layer is also known as the Internet layer. It deals with the
distribution of packets around the network. All routing occurs at this layer. The network layer
12
includes IP (Internet Protocol), ICMP (Internet Control Message Protocol), and IGMP
(Internet Group Management Protocol).
 The Transport Layer. This layer provides the flow of data between two hosts, for the
application layer above. In the TCP/IP protocol suite there are two different transport
protocols: TCP (Transmission Control Protocol) and UDP (User Data-gram Protocol).
 The Application Layer. This layer handles the details of the particular application. It
consists of SMTP, FTP, NFS, Telnet and Remote Login.
 Transmission Control Protocol (TCP). The Transmission Control Protocol (TCP) is a
protocol that provides a reliable stream delivery and connection service to applications. TCP
uses sequenced acknowledgement and is able to retransmit packets as needed. TCP is
described in RFC 793 and is the basic communication language or protocol of the Internet.
2.4 IP
The Internet Layer Protocol (IP) manages how packets are delivered to and from servers and
clients. It is probably the most dominant internetworking protocol in the world. These are its
main functions:

 Addressing and routing – it enables packets to be delivered to a specific destination.
IP knows the location of the gateway on the network. The gateway then interconnects
the network. There after data is passed from the node to the gateway.
 Fragmentation and reassembly – sometimes segments of applications do not fit inside
an IP packet, due to this they are fragmented.
 Detection and correction of data damaged in transit – the node which detects the error
reports this to the source node. A packet could also be lost and again an error message
will be submitted. It will also return an error if the network does not exist.
2.4.1 IP Addresses and Host Names
When a system is part of a TCP/IP network, it needs to have an identification address. This
address, called the IP or Internet Protocol address, is a 32-bit number that is usually represented
by four numbers separated by periods. An example is 190.137.48.1. This is the decimal
representation of four bytes. When assigned to your computer, this number is its node address,
whether your system is attached to the Internet, to your company LAN, or to a system of two
computers at home that you have attached in a small local LAN.
2.5 Ports
The TCP/IP protocol is used for communication between computer systems. Port numbers are
used for communicating between applications on the two systems. Ports are also called sockets.
This is the origin of the Winsock terminology.
When two applications are communicating by using the TCP/IP protocol, the applications use
port numbers to identify themselves to the other application. When a server receives a request for
a connection, the request is directed to a particular TCP/IP port. The server then knows which
application is being contacted because it has the port number associated with the application.
This is analogous is like having two phones in your house, one for business and one for personal
use. Servers listen on a particular port, and clients send requests to that port. In the everyday
world of Internet usage, there are well known ports. Some of these ports have become standard.
The World Wide Web uses Port 80, and FTP uses Port 21. WWW would function just as well on
13
Port 37, but everyone has agreed that Port 80 will be used. This is similar to the use of 999 for an
emergency phone number.

A particular server application listens on a specific port number for requests to connect to that
server. If you have a system that is used for both WWW and FTP, it will listen on both Ports 21
and 80. If the request for connection comes in on Port 80, the Web server application handles the
communication.

Having a system work as a server for one application does not prevent it from being a client for
another application. A system can be a Web server listening on Port 80 and communicate
contemporaneously with another system on another Port for a different application.

An important point to remember is that the client system does not have to send the request for
service from the same port on which the server is listening. For example, if the server ABC
application is listening on Port 239, the client may send its request for service from its Port 1593
to the server's Port 239. This works because the client tells the server the port number that its
request came from, so the server responds to the client by sending the response to Port 1593.
The essential parts of the message sent from one computer system to another are the following:
 Destination IP Address This is a dotted quartet for example, 191.187.39.55. This is how
the network identifies the node of the network for which the message is bound.
 Origin IP Address This is also a dotted quartet; it is used if any replies or requests for
retransmission are required.
 Destination Port Number This identifies the socket for which the message is bound.
Because sockets or ports are linked or bound to one application, this is the "address" of
the application on the system.
 Origination Port Number This is used for any replies that are sent to the originating
system to identify to the TCP/IP protocol. This application is the intended recipient of the
message.
 Data This is the information that the applications are sending to each other.
2.6 Protocols
2.6.1 SMTP (Simple Mail Transfer Protocol)
SMTP (Simple Mail Transfer Protocol) is a TCP/IP protocol used in sending and receiving E-
mail. However, since it's limited in its ability to queue messages at the receiving end, it's usually
used with one of two other protocols, POP3 or IMAP that let the user save messages in a server
mailbox and download them periodically from the server. In other words, users typically use a
program that uses SMTP for sending E-mail and either POP3 or IMAP for receiving messages
that have been received for them at their local server. SMTP usually is implemented to operate
over TCP port 25. The details of SMTP are in RFC 821 of the Internet Engineering Task Force
(IETF).
14
2.6.2 Telnet
Telnet is the way to access someone else's computer, assuming they have given permission.
(Such a computer is frequently called a host computer.) More technically, Telnet is a user
command and an underlying TCP/IP protocol for accessing remote computers. The Web or
HTTP protocol and the FTP protocol allow to request specific files from remote computers, but
not to actually be logged on as a user of that computer. With Telnet, it is necessary to log on as a
regular user with whatever privileges granted to the specific applications and data on that
computer.

The result of a request would be an invitation to log on with a userid and a prompt for a
password. If accepted, the remote user would be logged on like any user who used this computer
every day.

Telnet is most likely to be used by program developers and anyone who has a need to use
specific applications or data located at a particular host computer.

2.6.3 File Transfer Protocol (FTP)
FTP is the TCP protocol that is widely used to transfer files. There are two types of connections
established in an FTP session: a control connection and a data connection.

FTP (File Transfer Protocol), a standard Internet protocol, is the simplest way to exchange files
between computers on the Internet. Like the Hypertext Transfer Protocol (HTTP), which
transfers displayable Web pages and related files, and the Simple Mail Transfer Protocol
(SMTP), which transfers e-mail, FTP is an application protocol that uses the Internet

s TCP/IP
protocols. FTP is commonly used to transfer Web page files from their creator to the computer
that acts as their server for everyone on the Internet. It's also commonly used to download
programs and other files to your computer from other servers.

As a user, you can use FTP with a simple command line interface (for example, from the
Windows MS-DOS Prompt window) or with a commercial program that offers a graphical user
interface. Web browsers can also make FTP requests to download the selected programs from a
Web page. Using FTP, it is possible to update (delete, rename, move, and copy) files at a server.
It is necessary to log on to an FTP server. However, publicly available files are easily accessed
using anonymous FTP.

Basic FTP support is usually provided as part of a suite of programs that come with TCP/IP.
However, any FTP client program with a graphical user interface usually must be downloaded
from the company that makes it.

Control Connection The control connection, which is maintained throughout the FTP session, is
used to transmit commands between the client and the server. The first step in the FTP session
process consists of the server listening on FTP's well-known port, Port 21. The FTP server listens
by performing a passive open of a control connection, which waits for an active open control
connection request.
The second step in the FTP session process consists of the client sending an active open control
connection request to the FTP server, which request is addressed to Port 21. If all of the logon
requirements are met, an active control connection is created between the client and the server.
15
This connection stays open throughout the FTP session. Commands and replies are
communicated over this connection.

Data Connection A data connection is established each time a file is transferred and is
maintained only so long as the file transfer is in process. The client establishes a data connection
to either upload or download a file. When the file has been transferred, the data connection is
terminated.
When the client is finished with the FTP session, a command terminating the control connection
is sent to the server and the FTP session is terminated.
2.6.4 Hypertext Transfer Protocol (HTTP)
HTTP is one of the protocols that uses the basis of TCP/IP in a specific implementation. This is
the protocol of the World Wide Web. HTTP currently is in version 1.0 and moving toward
version 1.1. Most Web servers will be updated in the near future to support 1.1, as will Web
browsers. There will be backward compatibility for both servers and browsers. HTTP is a very
simple protocol. The client, usually called a browser, issues a request to the server. The server
responds with the requested file and closes the connection.

There are two HTTP message types: requests and responses. There are three types of requests:
GET, HEAD, and POST. In a GET request, a file is requested. In a HEAD request, only the
server header information is returned. In a POST request, the BODY is transmitted to the server,
and it contains data such as an HTTP form or a MAIL message.
HTTP Request The format of an HTTP request is the following:
request-line
headers (0 or more)
<blank line>
body (only for POST requests)
The format of the request-line is:
request request-URL HTTP/Version
An example of a request-line is:
GET /afile.htm HTTP/1.0
HTTP Response The format of the HTTP response is:
status-line
headers (0 or more)
<blank line>
body

The body usually will be an html file that contains formatting tags and links that are used in other
requests. The format of the status-line is:
HTTP/version response-code response-phrase
An example of a status-line is:
HTTP/1.0 200 OK
There are a number of other status codes. If you have spent any time on the Web, you have seen
the 404 Not Found response.
16
2.7 Object Oriented Design
For this project Visual Basic was chosen as it allowed the controlling of a computer quite easily,
this is referred to as socket programming. It is relatively easy to build complex applications with
Visual Basic.
2.8 Visual Basic WinSock
Visual Basic has a WinSock control which allows the connection of hosts in a network. It does
support TCP. The object of this WinSock has these properties like:

Obj.RemoteHost – this shows the IP address or the domain name
Obj.LocalPort – this shows the local port number

These are the methods that are used with the WinSock Object:

Obj.Connect – Connects to a remote host
Obj.Listen – Listens for a connection
Obj.GetData – Reads data from the input stream
Obj.SendData – Sends data to an output stream

These are the main events:

ConnectionRequest – when a remote host wants to make a connection with a server
DataArrival – when data has arrived from a connection

It is also possible in Visual Basic to have multiple connections to the server. Every time there is
a new connection a new one will be created.

These are events and methods used in the program:
Connect Event
This event connects to a server.
Private Sub Object.Connect (ErrorOccurred As Boolean)

Close Event
This event occurs when the remote computer closes the connection.
Object_Close()

DataArrival event
This event occurs when new data is received and the number of bytes returns.
Object_DataArrival (bytesTotal As Long)

Bind method
This specifies the local port and the IP address which used in TCP connections.
Object.Bind LocalPort, LocalIP
17

Listen method
This creates a socket and activates the listen command.
Object.Listen

Accept method
This accepts incoming connections after an event.
Object.Accept requestID

Close method
This closes the TCP connection.
Object.Close

SendData method
This sends data to a remote computer.
Object.SendData

GetData method
This gets data from an object.
Object.GetData

2.8 Conclusion
This chapter has described all the basics of networking including the OSI model. These seven
layers are crucial to the entire model. TCP/IP protocols interact with these layers at different
levels in the model. TCP/IP is an amazing protocol as it can be run over many computers on a
network. As networks are always expanding TCP/IP has been able to cope with this demand very
well.

Using TCP/IP any person in the world regardless of their location can communicate freely with
another person on a computer. Resources can be shared like printers and disks.

As you can see from this chapter there are many technical aspects related to the movement of
packets across a network. That’s the reason why TCP and IP are joined so closely together. Each
of them have critical jobs to perform and to a high standard. TCP/IP is very reliable.
18
3 Design

3.1 Introduction
This section describes the requirements that the system will be expected to achieve. This will
show exactly what is required of the software but will not show how the solution will be
implemented.
3.1.1 Specification
3.1.2 Purpose
The demonstration program will show how the implementation of the protocols is achieved. The
implementation will comprise of a Server program and a Client program. For this demonstration,
only one Client will be given access to the Server at one time. The Client will have the ability to
terminate the Server remotely.
3.1.2 Hardware
This program has been designed to be hardware independent, that is with the configuration has
been designed to run on any system that supports sockets. The system also has to have Internet
connectivity to allow use of the sockets and TCP, which the program requires.
3.1.3 Quality Goals
Quality goals have been based around McCall’s
1
model
3.1.4 Portability
Portability has been built into the project in that it is adaptable to any other system that supports
the software requirements of the project. It is easy when compiled to install it onto the system
required. It will also conform to set standards of portability.
3.1.5 Efficiency
Efficiency, this applies to all resources that system uses, hardware, software, personnel and any
other resource the system uses.

The result of the project must be fit for the purpose for which it was intended. The specification
must be satisfied.

This project has not been optimised for performance but will work on an acceptable time frame
for the users.



1
McCall, Generic fixed model approach of quality & ISO 9126.
19
3.1.6 Reliability
Reliability, this means the system must be relied on, and must be sound and consistent whenever
used. This does not take into effect off the ground between the Client and Server. The Internet
has its own built in problems with regard to reliability and is beyond the scope of this project.
3.1.7 Maintainability
Maintainability as most of this program is concrete and well documented it should pose little
difficulty in maintenance. The parts that are maintainable are the Client/Server side of things. It
will also be easy to upgrade.
3.1.8 Usability
Usability, applies to all programs, if they cannot be used for the purpose which they are designed
then the wrong product has been built. Usability will cover the speed of response for the user, as
well ease of use.
3.1.9 Functionality
Functionality, in this project will meet the requirements laid down in this specification
document. The needs of the project are laid down at the beginning of this document under the
title purpose.

3.2 Project Requirements
3.2.1 Project Specific Requirements
This document lays down the specific goals of the project, addressing only the issues covered
here. For the demonstration of the implementation into one or more of the TCP/IP protocols.
With these goals implemented, you can communicate with any given TCP/IP protocol. The
Client will make requests for a given protocol to the server, which will respond with a basic set
of responses.
3.2.2 Specific areas of exclusions from the project
Only a few protocols will be implemented as there are virtually thousands of protocols in the
RFC documents.
Client/Server Design
This document lays down the stages of this design, these are getting the vehicle of the project
designed. That is the Client/Server initial protocol program. The requirements will be met, if
implemented correctly.
3.2.4 Client/Server
Client/server describes the relationship between two computer programs in which one program,
the client, makes a service request from another program, the server, which fulfils the request. ln
a network, the client/server model provides a convenient way to interconnect programs that are
distributed efficiently across different locations. Computer transactions using the client/server
model are very common.

20
The client/server model has become one of the central ideas of network computing. Most
business applications being written today use the client/server model. So does the Internet's main
program, TCP/IP. In marketing, the term has been used to distinguish distributed computing by
smaller dispersed computers from the "monolithic" centralised computing of mainframe
computers. But this distinction has largely disappeared as mainframes and their applications have
also turned to the client/server model and become part of network computing.

In the usual client/server model, one server is activated and awaits client requests. Typically,
multiple client programs share the services of a common server program. Both client programs
and server programs are often part of a larger program or application. A computer with TCP/IP
installed allows making client requests for files from File Transfer Protocol (FTP) servers in
other computers on the Internet.
TCP/IP is not merely a pair of communication protocols but is a suite of protocols, applications
and utilities. Increasingly these protocols are referred to as the Internet Protocol Suite.
3.3 Client/Server Design
The Client/Server paradigm was chosen to meet the needs of a distributed computing
environment. It should appear as if it was a non-distributed application. The Client/Server
paradigm belongs to the Application layer in the OSI model as peer to peer communication. In
this demonstration, the Server will be limited to processing one Client at a time for simplicity.
The server is TCP based and this allows you to establish end to end connection between the two
communicating hosts. TCP provides reliability with a mechanism called Positive
Acknowledgement with Retransmission (PAR). A system using PAR sends the data again, unless
it hears from the remote system that the data arrived okay. The control is handled by a three-way
handshake. A unit of data sent between Client and the Server is called a segment.

The Client always initiates the conversation, and the server must provide appropriate answers. At
any point, if either party does not keep the exchange going, the connection is broken and the
conversation ends. If the conversation ends without the proper cleanup, the conversation cannot
be reinitiated until the applications have been reset.

3.3.1Designing the Client
When designing this sample client application, the user would want to see messages and replies
in two separate text boxes. RichTextBoxes were selected because of their capability to use text
formatting, and these text boxes were designated InBound and OutBound. A command button
was added to initiate the connection.

Two more text boxes were added to enter the remote host name or IP address and the remote
port, which enables the host and port to be selected and set at run time.
A final text box was added to display the local port number. This local port number can be read
before the connection is created and after the connection is made.
And last, but certainly not least, a Microsoft Winsock Control 6.0 is added. This Winsock
Control manages the communications between the client and server systems.

21
Client Design

What the Client has to do
1. Use Transmission Control Protocol (TCP).
2. Be able to connect to the Server.
3. Be able to terminate its session with the Server.
4. Allow a Client to terminate its session and terminate the Server.

How the Client communicates with the Server

The Client has the job of sending requests to the Server and waiting for a reply.
To carry out these communications tasks the Client uses the TCP/IP socket interface.

Sequence of calls made by the Client using TCP

1. Create a socket and connect to the Server via IP address.
2. Write to the Server a request until the user requests a quit selected.
3. Read back the response from your request then repeat write read cycle.
Close the socket when finished with the service.
Laying Out the Form
When the application runs, you need to enter the remote host name or IP address and the remote
port number before clicking the Connect button. After the connection is established, you can
enter text in the Outbound Text box. When entered, text is automatically dispatched to the Server
application. When you enter a character in the Outbound text box, a change event is triggered,
and its attached event handler sends the contents of the text box to the remote host.
Server Design
What the Server has to do.
1. Use Transmission Control Protocol (TCP).
2. Respond to one Client at a time, this makes the Server Iterative.
3. Allow a Client to terminate its session.
4. Allow a Client to terminate its session and terminate the Server.
How the Server communicates with the Client
The Server has the job of responding to a Client, this means that the Server has to wait for a
Client to make a contact, carry out a command and respond with an answer to the Client.
To carry out these communications tasks the Server uses the TCP/IP socket interface.
Sequence of calls made by the iterative Server using TCP

1. Create a master socket and bind to the well-known address for the service being
offered.
2. Make the Server ready for use.
3. Accept the next connection request from the socket.
22
4. Repeatedly read a request from the Client, formulate a response, and send a reply
back to the Client according to the application protocol.
3.4 Designing the Server
When the sample server application was designed, the primary requirement was that the
application be capable of servicing the needs of the client application. The server application
looks like a mirror image of the client application, with the exception that it cannot initiate a
connection.
The users see their messages and the replies in two separate text boxes. A text box is added to
display the Remote Port number. This enables you to see that the Local Port on the Client
Application and the Remote Port on the Server Application are the same.
Another text box is added to display the State property of the server. This changes from 2
(listening) to 7 (connected) as the application runs.

A final text box is added to display automatically the requestID that is sent by the client
application or, optionally, to display the Local Port number for the server.

Microsoft Winsock Control 6.0 is added to manage the communications between the client and
server systems. When the application runs, the server application is in a listening state. It waits
for a client system to initiate a connection.
3.4 Conclusion
The first step in the development was to create a very simple Server and a very small Client on
the same machine and make them communicate with no particular protocol. They were just
connected one to the other:

When the Client send data to the Server, typed on the keyboard, the Server print it on the screen
as soon as it is received.

The Server sends it back to the client that can read what he has sent.
It is easy to compare because the window send and receive of the Client are one under the other.

The second step was to design a fake Client able to connect to a real Server this time (DCS). The
difficulty was to find a port suitable for the tests. Therefore discovering other ports available was
very interesting. This version of the Client would send data to the Server that would send them
back (echo port).

The following version of the Client was able to connect to any port of DCS but they couldn't
communicate due to the fact that the Client did not have the protocol required. So the only way
to communicate with the Server was to enter the protocol directly in a dialogue box, and it is
possible to read the Server responses in a visualisation box. This method allows connecting to
any port in any protocol but requires the user to know every kind of protocol and it is not user
friendly for beginners. This method is then called manual method and kept in the latest version
of the Client. All the TCP/IP protocols are available on the Internet and could be found quite
easily because they are regrouped under a common category called RFC's, every protocol has a
RFC number where the protocol is well described.
23

To improve the SMTP protocol (E-mail). The Client had to send mails in an automatic way
(user-friendly). The problem was different this time, the protocol was known but this was a
matter of timing with the Serer. the program was too fast. So the add of a timer was necessary for
a constant timing independent of the machine employed. The last problem of the SMTP protocol
in automatic was the add of the return character to every line of protocol, that was a difficult bug
to find and it took a lot of time to find and quite none to solve. This version is addressed to the
DCS Server by default. The SMTP mode interface contains a box dedicated to the Server
answers to the protocol used by the program and the user can read the Servers answers.

Previous versions contained the manual mode and the SMTP mode in automatic working well
but there are some little bugs to be arranged not influent on the efficiency but on the ease to use.
The automatic mode allows to send mail through the DCS Server of Napier University from any
Email address (do not make any mistakes in your E-mail address) to any E-mail address on the
Internet.
The versions have been improved in many ways, such as:
The addition of the FTP mode. which supports only a few commands, but sufficient to test the
connection onto a real FTP server.

The addition of the Telnet mode. Which does NOT work, due to the complexity of the protocol.
-The design enhancement. The windows have been covered and the objects adapted.
-The code reduction. All the test lines and useless variables, code lines have been removed.

The last contains the most important evolution on the server application; such has the multiple
connection and the possibility to choose the 'listening' port. The main problem encountered is the
fact that a programme can only listen to ONE port to detect if a request for connection has
arrived from a client. So to test every port of a server it is needed to change the listening port.
The server can handle 4 simultaneous client connection real or not, and can be very easily
increased (the limit is 50-2000 depending on the type of computer). The client connected can be
from all over the Internet because the uses the IP address to connect (restricted to Napier due to
the Proxy). The client connected can be a real application, like FTP explorer, or the client of the
package.

The possibilities of the package are:

- Up to 4 clients (real or not) connected onto the Server Application, from anywhere.

- Indicator visual and audio present to underline the present state of the connection, on both
Server and Client side.

- Send plain text messages between Client and Server when the connection is established, in a
test purpose.

- Perform some basic functions of an FTP client. [FTP mode]
Send E-mails through a real mail server in automatic plain text). [SMTP mode] Connect onto any
server and any open port. But no protocol given. [Manual mode]
24
4 Testing
4.1 Introduction
This section covers the testing of the software package. Testing is a crucial part in the successful
implementations of the protocols. As the requirements have now been established, it is now
crucial that a test plan be devised so that we can establish whether or not the system meets the
requirements. Also if it works as expected. Portability is made easy by using Winsock Control,
this guarantees true portability using industry standards. Efficiency, comes down to how fast the
communications between the Client and Server perform. Reliability is mainly down to the
system set-up and implementation of protocols. The TCP protocol is considered reliable.
Maintainability, of the program is of the minimum as it is a straightforward Client/Server set-up
and has been well documented. Usability has been addressed with an easy to follow menu system
for both the Server and the Client. Functionality, have also been addressed and tested. All stages
were met and satisfied.
4.2 Test Plan
1. The Telnet Test
As this part did not work, there is no test available. The main reason behind this was due to the
fact that the protocol was not understood, but it did connect.

2. The SMTP Test
To test the SMTP, an email is sent through the server, using the SMTP mode. Below shows how
this is achieved.

1. Select SMTP mode.
2. Type email address of the sender in the mail from box.
3. Type email address of the recipient in the mail from box.
4. Type a message in the box.
5. Choose a mail server.
6. Click on Send.

3. The HTTP Test
As this part did not completely work, there is no test available.

4. The FTP Test
The FTP can perform only very basic commands, like login, create a directory or delete it. This
is the way it will work.

1. Select FTP mode.
2. Type in an IP address.
3. Select a port number.
4. Click on Connect.
5. Type in a command.
6. Click on Send.
25
Problems
At first the number of object was not a problem at all. They were a few. But during the
development the number of object increases and 3 solutions were possible.

Duplicate the Client application to have one form by mode, but this solution is slow to pass from
one mode to the next.

Modify the size and function of each object to reduce their number and have only very few
object with lots of modes and functions, but it's very complicated and the event handling would
be too complicated.

Superpose the objects and use the 'visible' function to show or hide them, but it requires lots of
initialisations.

The last one has been chosen because even if the code is longer, it is far simpler to build and
debug.

Initialisation
This is the following problem, due to the number of objects and the need to switch from one
mode to another, lots of show and hide objects is necessary. Anyway the comfort of use and the
flexibility of programmatic is so much increased.

Read codes from servers
The basic functions were to send and receive data, and to connect onto a real server is one of the
first steps. The thing to note is that each response of the server includes a specific code. And in
those response lye two necessities, make the program understand those codes, and for the server
part, create those codes. Later on, the software would only contain 2-3 of those codes, such as:
220: acknowledgements of command, ready, ok...
250: mail from ok, rcpt ok, messages sending ok...

354: start message + end of message character.
4.3 Conclusion
This chapter has illustrated the Testing side of implementing protocols. It has shown in this
chapter that a lot of testing will be required. Each protocol would have to go through large
amounts of testing. However as this does take up a considerable amount of time, it will only
mean the protocol implementation will run successfully for a long time.

26
5 Implementation
5.1 Introduction
This section details the implementation of the protocols adopted. It illustrates the User
commands for TCP/IP, FTP, Telnet, SMTP.
5.2 FTP Implementation
Sending files to another computer is very important. An effective way of doing this is to use
FTP.
When you open an FTP connection, you are connected to ports 20 and 21. Port 20 is the data port
and port 21 is the control port. The FTP program uses TCP/IP to transfer files to and from nodes.
Some commands are very similar to DOS commands, such as cd (change directory), dir (list
directory), open (open node).

In FTP if you send a command such as get thisfile, the response will be:

200 PORT command successful
150 Opening ASCII mode data connection for .message
226 Transfer Complete
local: .message remote: .message
135 bytes received in 1.4 seconds (0.09 Kbytes/s)

These are some of the FTP commands:

ABOR: abort previous FTP command and any data transfer
LIST filelist: list files or directories
PASS password: password on server
PORT: n1,n2,n3,n4,n5,n6: client IP address and port
QUIT: logoff from server
RETR filename: get a file
STOR filename: store a file
SYST: server returns system type
TYPE type: specify file type
USER username: username on server

In order to make FTP workable without needless error messages, the
following implementation is required for all servers:

TYPE - ASCII Non-print
MODE - Stream
STRUCTURE - File, Record
COMMANDS - USER, QUIT, PORT,
TYPE, MODE, STRU,
for the default values
RETR, STOR,
NOOP.
27

These are the default values for transfer parameters are:

TYPE - ASCII Non-print
MODE - Stream
STRU - File

Here are some replies given, along with the message string:

 125 Data connection already open; transfer starting.
 200 Command OK
 214 Help message
 331 Username OK, password required
 425 Can’t open data connection
 452 Error writing file
 500 Syntax error unrecognized command
 501 Syntax error invalid arguments
 502 Unimplemented MODE type.

FTP command generates an online reply like:

 221 Goodbye

There are three uses for the data connection:

1. Sending a file from the client to the server.
2. Sending a file from the server to the client.
3. Sending a listing of files or directories from the server to the client.

5.3 SMTP Implementation
The email is most probably the one of the most popular applications. Commands are sent by the
client to the server, and the server responds back with numerical codes. This is what happens
when we send mail:

Sun % mail –v 96046848@napier.ac.uk
To: 96046848@napier.ac.uk
Subject: testing

1,2,3.
.
Sending letter…96046848@napier.ac.uk…

Connecting to mailhost via ether…
Trying 111.111.1.11… connected.
220 napier.ac.uk Sendmail date and time

Only five commands are used to send the mail: HELO, MAIL, RCPT, DATA and QUIT.
28
After the subject is entered, we then type in the message. The client does the active open to TCP
port 25. It waits for a return message from the server. The server response will be the domain
name. Next the client identifies itself with the HELO command. The MAIL command identifies
the originator of the message and the RCPT identifies the recipient. Then by using the DATA
command, the message contents are sent. The last command is QUIT, which terminates the mail
exchange.

The SMTP mode was required to work in automatic, so the protocol needed to be entered by
software, to be followed and dialogue with the mail server properly. Then the main requirement
was to send right line of protocol, at the right time. This is where the server codes are important.
To establish a connection to a server it is necessary to follow this sequence:

- Choose the IP or DNS address of the server.
- Then the port (25 for SMTP).
- And last use the 'connect' command.

Wait for a response from the server. To read that response, a filter is necessary to isolate the 3
first digits of the data received. Those digits are the response server codes.

If the code is 220 then the connection is successfully established. And it
is possible to enter the

SMTP protocol:

Connection established
220

'MAIL FROM'~E-mail address
250

'RCPT TO' + E~maiI address
250

'DATA'
354

Message (plain text) +'.' on a line
250

'QUIT'


Figure 5-1: SMTP protocol sequence.

29

An important point is that when a command line is sent to a server, it must be ended by two
characters: line-feed (10 in ASCII) and carrier-return (13 in ASCII).
Server problems

The term server may seem very large and it is difficult to know where to start. To be simple, it is
an application which 'listen' one or more ports, to detect if a Client wants to connect (request). It
can handle one or multiple Client at a time. It is made in the purpose of remote connection and
service.

The first step is to choose a port to listen to. Then accept only one connection, otherwise it will
crash, and send a welcome message (220 + message). When it works, it is possible to make
dialogues boxes to send and receive message once connected. And last, add command
understood by the server, like:

- QUIT: closes the connection with the server properly.

- HELO: returns a message from the Server containing its 'P address, the 'P address of the
Client performing the command and a polite 'pleased to meet you'.

Client problems

It is far more interesting if the server can accept more than one request and handle many clients
simultaneously. The fact is that it is not possible to connect many clients on one socket so the
best way is to open many sockets and then create some kind of mini server each one treating one
client. To control this, a listening procedure that accepts, and attributes client to free sockets. The
server created has been realised to handle 4 clients, but can be VERY easily expanded to a limit
of 50-2000 sockets depending on the computer another limitation is the size of the form which
must contain all the objects. This problem can be avoided by some kind of mode switch
procedure.

A little problem was the fact the send of a last message before disconnection was necessary on
the server side, because real server have one. And the difficulty is that if the close command
occurs just after the send of the last message, the message seam not to be sent. Therefore a timer
was necessary to close the connection about 1 sec. after the closing message.

5.4 TCP Implementation
TCP is a connection-oriented, reliable transport protocol. A connection-oriented protocol implies
that the two hosts participating in a discussion must first establish a connection before data may
be exchanged. In TCP’s case, this is done with the three-way handshake. Reliability can be
provided in a number of ways, like data sequencing and acknowledgement. TCP assigns
sequence numbers to every byte in every segment and acknowledges all data bytes received from
the other end.

In order to exchange data using TCP, hosts must establish a connection. TCP establishes a
connection in a 3-step process called the 3-way handshake. If machine A is running a Client
program and wishes to connect to a Server program on machine B, the process is as follows:
30


a. A sends SYN to B
b. A receives SYN/ACK from B
c. A sends ACK to B

At a., the Client is telling the server that it wants a connection. This is the SYN flag’s only
purpose. The Client is telling the Server that the sequence number field is valid, and should be
checked. The Client will set the sequence number field in the TCP header to its ISN (initial
sequence number). The Server, upon receiving this segment. will respond with its own ISN (
therefore the SYN flag is on) and an Acknowledgement of the Client’s first segment (which is
the Client’s ISN+1). The Client then Acknowledges the Server’s ISN c. Now data transfer may
take place.
5.6 Conclusion
This chapter has demonstrated how you can use Telnet, SMTP and FTP to connect to and use
several other TCP/IP services. Implementation of any given protocol must comply to the rules
set out in RFC documents. These documents are the origination of the protocols and provide
many useful insights into any given protocol.

Within these RFC documents are many User commands which prove to be very helpful. They
describe the history of these protocols. As the Internet is always growing its hard to tell what
future will hold for the various protocols.
31
6 6 Conclusion
As the software stands, HTTP and other protocols were not implemented to success due to the
time factor. At this stage, the manual connection to any port of any Server is working, so is the
SMTP protocol in automatic, with no restriction concerning the servers. The FTP mode is,
concerning the project requirement, achieved, but can be improved if it is needed. Unfortunately,
the Telnet is not really a success, it only connects, but the Telnet protocol needs a lot of
parameters and exchanges between the client and the server, and the code appears to be in 7-bit
ASCII instead of the 8-bit windows ASCII. To improve this last mode, a lot of changes are
necessary and the code largely complicated.

The Client software was the first part of the project and was a bit late in the timescale. The
Server side was very hard to start but a lot of researched over the web and on line tutorials were
very useful. The difficulty was that the solutions provided were created to fit Visual Basic 6,
version more recent than Napier's one. But the structure, quite complex, was understandable, and
successfully implemented into the project's code.

The Server is, for me, was a success, as well as the Client which the possibilities are easily
extendable, and would suit a slightly different subject. The Server is complete about the
connection, but can be upgraded not only on the number of Client connected, but also on the
treatment of the information. It can be dedicated to one port and become only an FTP Server, or
anything else, by adding the corresponding code.

This project was very interesting. I didn't know Visual Basic at all when I started this project. It
was a good experience learning it. It is a very useful development tool, especially for socket
programming. The software can be upgraded in future, to include the implementation of further
protocols.

32
Appendix 1
Documentation and Screen Shots
The software will run on any Windows PC. You will not have to install Visual Basic 6.
The program is called TCP/IP Emulator. By clicking the program you will see an option screen
for a Client or a Server program. By clicking on the protocol buttons will allow you access to the
TCP/IP protocols.





33
Appendix 2
RFC’s

All the required commands, rules and order of entering commands you can find in
RFC (request for comments) documents.

Protocol RFC Link
SMTP 821 http://www.faqs.org/rfcs/rfc821.html
POP3 1725 http://www.faqs.org/rfcs/1725.html
HTTP 2068 http://www.faqs.org/rfcs/rfc2068.html
FTP 959 http://www.faqs.org/rfcs/rfc959.html

Above are just a few of the thousands of RFCs available. The set of commands and
responses is unique for every protocol.


34
Appendix 3
Source Code

Client Code

'Last modification: 20/04/2001 FTP & SMTP & Manual mode only
Dim Mode As String
Dim ProtocolSMTP As Integer
Dim CounterOk As Integer
Dim LoopCount As Long
Dim Temps As Long
Dim ModeSMTP As Integer

Private Sub Form_Load()
Unload ChoiceSC 'Close the main menu properly
SendTextData.Enabled = False 'Initialisation
SendTextDatalbl.Enabled = False
cmdDisConnect.Visible = False
cmdConnect.Visible = True
AddressIP.Enabled = True
AddressPort.Enabled = False
PortNameC.Visible = False 'Init manual mode
AddressPort.Visible = False
AddressIP.Visible = False
PortNameClbl.Visible = False
AddressPortlbl.Visible = False
AddressIPlbl.Visible = False
cmdConnect.Visible = False
cmdDisConnect.Visible = False
SendData.Visible = False
SendTextData.Visible = False
ShowText.Visible = False
SendTextDatalbl.Visible = False
ShowTextlbl.Visible = False
ConnectionStateM.Visible = False
ConnectionStateMlbl.Visible = False
red.Visible = False
green.Visible = False
Radiation.Visible = False
MailFrom.Visible = False 'Init SMTP mode
MailTo.Visible = False
Message.Visible = False
MailFromlbl.Visible = False
MailTolbl.Visible = False
Messagelbl.Visible = False
ServerAnswer.Visible = False
35
ServerAnswerlbl.Visible = False
ResetSMTP.Visible = False
FtpServerAnswer.Visible = False 'Init FTP mode
FtpCommand.Visible = False
FtpCommandlbl.Visible = False
FtpServerChoice.Visible = False
FtpServerChoicelbl.Visible = False
FtpPortChoice.Visible = False
FtpPortChoicelbl.Visible = False
ResetFTPTelnet.Visible = False
SendData.Caption = "Send"
FtpTelnetSend.Visible = False
TelnetServerAnswer.Visible = False 'Init TELNET mode
TelnetCommand.Visible = False
TelnetCommandlbl.Visible = False
TelnetServerChoice.Visible = False
TelnetServerChoicelbl.Visible = False
TelnetPortChoice.Visible = False
TelnetPortChoicelbl.Visible = False
ResetFTPTelnet.Visible = False
SendData.Caption = "Send"
FtpTelnetSend.Visible = False
CounterOk = 0 'Init variables
ModeSMTP = 0
End Sub

Private Sub Ftp_Click()
Mode = "FTP"
FtpServerAnswer.Text = ""
TelnetServerAnswer.Visible = False 'Disable TELNET mode
TelnetCommand.Visible = False
TelnetCommandlbl.Visible = False
TelnetServerChoice.Visible = False
TelnetServerChoicelbl.Visible = False
TelnetPortChoice.Visible = False
TelnetPortChoicelbl.Visible = False
ResetFTPTelnet.Visible = False
SendData.Caption = "Send"
FtpTelnetSend.Visible = False

FtpServerAnswer.Visible = True 'Enable FTP mode
FtpCommand.Visible = True
FtpCommandlbl.Visible = True
FtpServerChoice.Visible = True
FtpServerChoicelbl.Visible = True
FtpPortChoice.Visible = True
FtpPortChoicelbl.Visible = True
ResetFTPTelnet.Visible = False
SendData.Caption = "Connect"
FtpTelnetSend.Visible = False
36
red.Visible = True
green.Visible = False
Radiation.Visible = False
PortNameC.Visible = False 'Disable manual mode objects
AddressPort.Visible = False
AddressIP.Visible = False
PortNameClbl.Visible = False
AddressPortlbl.Visible = False
AddressIPlbl.Visible = False
cmdConnect.Visible = False
cmdDisConnect.Visible = False
SendData.Visible = True
SendTextData.Visible = False
ShowText.Visible = False
SendTextDatalbl.Visible = False
ShowTextlbl.Visible = False
ConnectionStateM.Visible = False
ConnectionStateMlbl.Visible = False

MailFrom.Visible = False 'Disable SMTP mode ojects
MailTo.Visible = False
Message.Visible = False
MailFromlbl.Visible = False
MailTolbl.Visible = False
Messagelbl.Visible = False
ServerAnswer.Visible = False
ServerAnswerlbl.Visible = False
ResetSMTP.Visible = False

End Sub

Private Sub Manuel_Click()
Mode = "Manual"
SendTextData.Text = ""
PortNameC.Visible = True 'Init Manual mode objects
AddressPort.Visible = True
AddressIP.Visible = True
PortNameClbl.Visible = True
AddressPortlbl.Visible = True
AddressIPlbl.Visible = True
cmdConnect.Visible = True
cmdDisConnect.Visible = False
SendData.Visible = False
SendTextData.Visible = True
ShowText.Visible = True
SendTextDatalbl.Visible = True
ShowTextlbl.Visible = True
ConnectionStateM.Visible = True
ConnectionStateMlbl.Visible = True
ConnectionStateM.Text = "Disconnected"
37
red.Visible = True
green.Visible = False
Radiation.Visible = False
MailFrom.Visible = False 'Disable SMTP mode ojects
MailTo.Visible = False
Message.Visible = False
MailFromlbl.Visible = False
MailTolbl.Visible = False
Messagelbl.Visible = False
ServerAnswer.Visible = False
ServerAnswerlbl.Visible = False
ServerAnswer.Visible = False
ServerAnswerlbl.Visible = False
ResetSMTP.Visible = False
FtpServerAnswer.Visible = False 'Disable FTP mode
FtpCommand.Visible = False
FtpCommandlbl.Visible = False
FtpServerChoice.Visible = False
FtpServerChoicelbl.Visible = False
FtpPortChoice.Visible = False
FtpPortChoicelbl.Visible = False
ResetFTPTelnet.Visible = False
SendData.Caption = "Send"
FtpTelnetSend.Visible = False
TelnetServerAnswer.Visible = False 'Disable TELNET mode
TelnetCommand.Visible = False
TelnetCommandlbl.Visible = False
TelnetServerChoice.Visible = False
TelnetServerChoicelbl.Visible = False
TelnetPortChoice.Visible = False
TelnetPortChoicelbl.Visible = False
ResetFTPTelnet.Visible = False
SendData.Caption = "Send"
FtpTelnetSend.Visible = False
End Sub

Private Sub Smtp_Click()
Mode = "SMTP"
PortNameC.Visible = False 'Disable manual mode objects
AddressPort.Visible = False
AddressIP.Visible = False
PortNameClbl.Visible = False
AddressPortlbl.Visible = False
AddressIPlbl.Visible = False
cmdConnect.Visible = False
cmdDisConnect.Visible = False
SendData.Visible = True
SendTextData.Visible = False
ShowText.Visible = False
SendTextDatalbl.Visible = False
38
ShowTextlbl.Visible = False
MailFrom.Visible = True 'Enable SMTP mode ojects
MailTo.Visible = True
Message.Visible = True
MailFromlbl.Visible = True
MailTolbl.Visible = True
Messagelbl.Visible = True
ServerAnswer.Visible = True
ServerAnswerlbl.Visible = True
ResetSMTP.Visible = False
ConnectionStateM.Visible = True
ConnectionStateMlbl.Visible = True
ConnectionStateM.Text = "Disconnected"
red.Visible = True
green.Visible = False
Radiation.Visible = False
FtpServerAnswer.Visible = False 'Disable FTP mode
FtpCommand.Visible = False
FtpCommandlbl.Visible = False
FtpServerChoice.Visible = False
FtpServerChoicelbl.Visible = False
FtpPortChoice.Visible = False
FtpPortChoicelbl.Visible = False
ResetFTPTelnet.Visible = False
SendData.Caption = "Send"
FtpTelnetSend.Visible = False
TelnetServerAnswer.Visible = False 'Disable TELNET mode
TelnetCommand.Visible = False
TelnetCommandlbl.Visible = False
TelnetServerChoice.Visible = False
TelnetServerChoicelbl.Visible = False
TelnetPortChoice.Visible = False
TelnetPortChoicelbl.Visible = False
ResetFTPTelnet.Visible = False
SendData.Caption = "Send"
FtpTelnetSend.Visible = False
End Sub

Private Sub Telnet_Click()
Mode = "TELNET"
FtpTelnetSend.Visible = False
PortNameC.Visible = False 'Disable manual mode objects
AddressPort.Visible = False
AddressIP.Visible = False
PortNameClbl.Visible = False
AddressPortlbl.Visible = False
AddressIPlbl.Visible = False
cmdConnect.Visible = False
cmdDisConnect.Visible = False
SendData.Visible = True
39
SendTextData.Visible = False
ShowText.Visible = False
SendTextDatalbl.Visible = False
ShowTextlbl.Visible = False
ConnectionStateM.Visible = False
ConnectionStateMlbl.Visible = False

MailFrom.Visible = False 'Disable SMTP mode ojects
MailTo.Visible = False
Message.Visible = False
MailFromlbl.Visible = False
MailTolbl.Visible = False
Messagelbl.Visible = False
ServerAnswer.Visible = False
ServerAnswerlbl.Visible = False
ResetSMTP.Visible = False
FtpServerAnswer.Visible = False 'Disable FTP mode
FtpCommand.Visible = False
FtpCommandlbl.Visible = False
FtpServerChoice.Visible = False
FtpServerChoicelbl.Visible = False
FtpPortChoice.Visible = False
FtpPortChoicelbl.Visible = False
ResetFTPTelnet.Visible = False
SendData.Caption = "Send"
FtpTelnetSend.Visible = False
TelnetServerAnswer.Visible = True 'Init TELNET mode
TelnetCommand.Visible = True
TelnetCommandlbl.Visible = True
TelnetServerChoice.Visible = True
TelnetServerChoicelbl.Visible = True
TelnetPortChoice.Visible = True
TelnetPortChoicelbl.Visible = True
ResetFTPTelnet.Visible = False
SendData.Caption = "Connect"
red.Visible = True
green.Visible = False
Radiation.Visible = False
End Sub

Private Sub cmdConnect_Click() 'Manual mode only
'Connect to the server
myTCPClient.Connect
If AddressPort.Text = "1001" Or AddressPort.Text = "21" Or AddressPort.Text =
"25" Then
ConnectionStateM.Text = "Connecting"
SendTextData.Enabled = False
red.Visible = False
green.Visible = False
Radiation.Visible = True
40
Else
ConnectionStateM.Text = "Connected"
SendTextData.Enabled = True
red.Visible = False
green.Visible = True
Radiation.Visible = False
End If
ShowText.Text = ""
SendTextDatalbl.Enabled = True
cmdConnect.Visible = False
cmdDisConnect.Visible = True
AddressIP.Enabled = False
AddressPort.Enabled = False
CloseC.Enabled = False
PortNameC.Enabled = False
Manuel.Enabled = False
Ftp.Enabled = False
Smtp.Enabled = False
Telnet.Enabled = False
End Sub

Private Sub myTCPClient_Close() 'Manual mode only
'Close method
myTCPClient.Close
ConnectionStateM.Text = "Disconnected"
ShowText.Text = (ShowText.Text + "> Connection Closed by Server" + Chr(13) +
Chr(10))
red.Visible = True
green.Visible = False
Radiation.Visible = False
SendTextData.Enabled = False
SendTextDatalbl.Enabled = False
cmdConnect.Visible = True
cmdDisConnect.Visible = False
AddressIP.Enabled = True
CloseC.Enabled = True
PortNameC.Enabled = True
Manuel.Enabled = True
Ftp.Enabled = True
Smtp.Enabled = True
Telnet.Enabled = True
End Sub

Private Sub cmdDisConnect_Click() 'Manual mode only
'Disconnect from the server
myTCPClient.Close
ConnectionStateM.Text = "Disconnected"
ShowText.Text = (ShowText.Text + "> Connection Closed by Client" + Chr(13) +
Chr(10))
red.Visible = True
41
green.Visible = False
Radiation.Visible = False
SendTextData.Enabled = False
SendTextDatalbl.Enabled = False
cmdConnect.Visible = True
cmdDisConnect.Visible = False
AddressIP.Enabled = True
CloseC.Enabled = True
PortNameC.Enabled = True
Manuel.Enabled = True
Ftp.Enabled = True
Smtp.Enabled = True
Telnet.Enabled = True
End Sub

Private Sub PortNameC_Click() 'Manual mode only
'Choice of the port (name)
If PortNameC.Text = "--Manual enter-- >" Then AddressPort.Enabled = True Else
AddressPort.Enabled = False
If PortNameC.Text = "Test" Then AddressPort.Text = "1001"
If PortNameC.Text = "Echo" Then AddressPort.Text = "7"
If PortNameC.Text = "Daytime" Then AddressPort.Text = "13"
If PortNameC.Text = "FTP" Then AddressPort.Text = "21"
If PortNameC.Text = "Telnet" Then AddressPort.Text = "23"
If PortNameC.Text = "SMTP" Then AddressPort.Text = "25"

End Sub

Private Sub ResetSMTP_Click() 'SMTP mode only
ResetSMTP.Visible = False
ServerAnswer.Text = ""
'Message.Text = ""
'MailFrom.Text = ""
'MailTo.Text = ""
myTCPClient.Close
red.Visible = True
green.Visible = False
Radiation.Visible = False
ConnectionStateM.Text = "Disconnected"
End Sub

Private Sub ResetFTPTelnet_Click() 'FTP & Telnet mode
If Mode = "FTP" Then
Smtp.Enabled = True
SendData.Enabled = True
Telnet.Enabled = True
Ftp.Enabled = True
Manuel.Enabled = True
CloseC.Enabled = True
FtpServerChoice.Enabled = True
42
FtpPortChoice.Enabled = True
ResetFTPTelnet.Visible = False
myTCPClient.Close
red.Visible = True
green.Visible = False
Radiation.Visible = False
FtpTelnetSend.Visible = False
End If
If Mode = "TELNET" Then
Smtp.Enabled = True
SendData.Enabled = True
Telnet.Enabled = True
Ftp.Enabled = True
Manuel.Enabled = True
CloseC.Enabled = True
TelnetServerChoice.Enabled = True
TelnetPortChoice.Enabled = True
ResetFTPTelnet.Visible = False
myTCPClient.Close
red.Visible = True
green.Visible = False
Radiation.Visible = False
FtpTelnetSend.Visible = False
End If

End Sub

Private Sub SendTextData_KeyPress(KeyAscii As Integer) 'Manual mode
'When you press the ENTER key the contain of the top box is sent
Dim Envoi As String
If Mode = "Manual" Then
If KeyAscii = 13 Then
Envoi = SendTextData.Text + Chr(10)
myTCPClient.SendData Envoi
SendTextData.Text = ""
End If
End If
End Sub

Private Sub AddressIP_Click() 'manual mode only