#include<iostream.h> inline float mul(float x, float y) { return(x*y); } inline double div(double p,float q) { return(p/q); } int main() { float a=12.345; float b=9.82; cout<<mul(a,b)<<"\n"; cout<<div(a,b)<<"\n"; return 0; }Output--->
Thursday, December 30, 2010
Inline Function
Wednesday, October 20, 2010
Tuesday, September 7, 2010
Avg. Of N No’s. Untill 0.
#include"stdio.h"> #include"conio.h" void main() { float avg,sum=0,count=0; int i,n,a; printf("Enter n no. values: "); printf("\nEnter values:"); for(i=1;i<=i;i++) { scanf("%d",&a); sum=sum+a; if(a==0) { avg=sum/(i-1); printf("\nAverage of %d No's. before 0: =%.1f",i-1,avg); } } getch(); }
Find out sum of N Numbers
#include"stdio.h" #include"conio.h" void main() { int i,n,a,sum=0; printf("Enter n no. values: "); scanf("%d",&n); printf("\nEnter values: "); for(i=1;i<=n;i++) { scanf("%d",&a); sum=sum+a; } printf("\n Sum of %d is= %d",n,sum); getch(); }
Find out sum of 10 numbers
#include"stdio.h" #include"conio.h" void main() { int i,n=10,a,sum=0; printf("Enter 10 Number Values:\n"); for(i=1;i<=n;i++) { scanf("%d",&a); sum=sum+a; } printf("\nSum of 10 Number is= %d",sum); getch(); }
Reverse of n Digit number
#include"stdio.h" #include"conio.h" void main() { int i,n,a,sum=0,x; printf("Enter n Digit Number: "); scanf("%d",&n); x=n; printf("\nReverse of %d number is: ",x); for(i=1;i<=n;i++) { a=n%10; n=n/10; printf("%d",a); } printf("%d",n); getch(); }
Odd Till 3 to 30
#include"stdio.h" #include<conio.h> void main() { int a,i,n=30; printf("Odd value till 30 are: \n\n"); a=30/2; for(i=0;i<=n;i++) { if(i%2==1) { if(i==1) printf(" "); else printf("%d ",i); } } getch(); }
Sum of n Digit numbers
#include"stdio.h" #include"conio.h" void main() { int i,n,a,sum=0,x; printf("Enter n Digit Number: "); scanf("%d",&n); x=n; for(i=1;i<=n;i++) { a=n%10; n=n/10; sum=sum+a; } sum=sum+n; printf("\nSum of %d numbers=%d",x,sum); getch(); }
Average of n numbers
#include#include void main( { float avg,sum=0; int i,n,a; printf("Enter n no. values: "); scanf("%d",&n); printf("\nEnter marks"); for(i=1;i<=n;i++) { scanf("%d",&a); sum=sum+a; } avg=sum/n; printf("\naverage marks=%.1f",avg); getch(); }
Friday, August 27, 2010
Piramid
#include<stdio.h> #include<conio.h> void main() { int i,j,k,n; printf("enter the no. '<20'"); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=1;j<=n-i;j++) { printf(" "); } for(k=1;k<=2*i-1;k++) { printf("*"); } printf("\n"); } getch(); }Output-->
Thursday, August 26, 2010
Greatest of Three Numbers
#include<stdio.h> void main() { int a,b,c; printf("Enter the Three Number:\n"); printf("First Number:"); scanf("%d",&a); printf("Second Number:"); scanf("%d",&b); printf("Third Number:"); scanf("%d",&c); if((a>b)&&(a>c)) printf("\n%d is greatest than other two's.",a); else if((b>a)&&(b>c)) printf("\n%d is greatest than other two's.",b); else printf("\n%d is greatest than other two's.",c); } OutPut---->
Monday, August 23, 2010
Introduction: C#
Welcome to the C# Station Tutorial. This is a set of lessons suited for beginning to intermediate programmers or anyone who would like to gain familiarity with the C# programming language. These lessons will help you get a quick head-start with C# programming.
To get started, you will need a compiler and an editor. There are several options for obtaining a compiler to write C# programs. A free option is to download the .NET Frameworks SDK and use Notepad. Of course there are many editor and IDE options available, so see the Tools section to select the option that's right for you. Most of the examples in these tutorials run as console programs. Microsoft Visual Studio .NET is also available in multiple versions as well as a free download for Visual Studio Express tools, including Visual C# Express.
This tutorial is a work in progress. It's quality is a product of volunteer reviews and valuable feedback received from many readers. Please visit periodically for the latest updates and new lessons.
Once you've completed this tutorial, you may be interested in additional resources to continue learning C#. There are additional Articles on this site and a Links section will guide you to many high-quality web sites that specialize in certain .NET technologies.
To get started, you will need a compiler and an editor. There are several options for obtaining a compiler to write C# programs. A free option is to download the .NET Frameworks SDK and use Notepad. Of course there are many editor and IDE options available, so see the Tools section to select the option that's right for you. Most of the examples in these tutorials run as console programs. Microsoft Visual Studio .NET is also available in multiple versions as well as a free download for Visual Studio Express tools, including Visual C# Express.
This tutorial is a work in progress. It's quality is a product of volunteer reviews and valuable feedback received from many readers. Please visit periodically for the latest updates and new lessons.
Once you've completed this tutorial, you may be interested in additional resources to continue learning C#. There are additional Articles on this site and a Links section will guide you to many high-quality web sites that specialize in certain .NET technologies.
Friday, July 30, 2010
Router
A router is similar in a switch in that it forwards packets based on address. But, instead of the MAC address that a switch uses, a router can use the IP address. This allows the network to go across different protocols.
The most common home use for routers is to share a broadband internet connection. The router has a public IP address and that address is shared with the network. When data comes through the router it is forwarded to the correct computer.
This comparison to email gets a little off base. This would be similar to the router being able to receive a packet as email and sending it to the user as a fax.
The most common home use for routers is to share a broadband internet connection. The router has a public IP address and that address is shared with the network. When data comes through the router it is forwarded to the correct computer.
This comparison to email gets a little off base. This would be similar to the router being able to receive a packet as email and sending it to the user as a fax.
Switch
A switch steps up on a bridge in that it has multiple ports. When a packet comes through a switch it is read to determine which computer to send the data to.
Switches on the other hand are more advanced.
Instead of broadcasting the frames everywhere, a switch actually checks
for the destination MAC address and forward it to the relevant port to
reach that computer only. This way, switches reduce traffic and divide
the collision domain into segments, this is very sufficient for busy
LANs and it also protects frames from being sniffed by other computers
sharing the same segment.
They build a table of which MAC address belongs to which segment. If a
destination MAC address is not in the table it forwards to all segments
except the source segment. If the destination is same as the source,
frame is discarded.
Switches have built-in hardware chips solely designed to perform
switching capabilities, therefore they are fast and come with many
ports. Sometimes they are referred to as intelligent bridges or
multiport bridges.
Different speed levels are supported. They can be 10 Mb/s, 100 Mb/s, 1 Gb/s or more.
Different speed levels are supported. They can be 10 Mb/s, 100 Mb/s, 1 Gb/s or more.
Most common switching methods are:
1. Cut-through: Directly forward what the switch gets.
2. Store and forward: receive the full frame before retransmitting it.
2. Store and forward: receive the full frame before retransmitting it.
OSI: Switches are on the data link layer (just above physical layer)
that’s why they deal with frames instead of bits and filter them based
on MAC addresses. Switches are known to be used for their filtering
capabilities.
Bridge
A bridge goes one step up on a hub in that it looks at the destination of the packet before sending. If the destination address is not on the other side of the bridge it will not transmit the data.
- A bridge only has one incoming and one outgoing port.
- To build on the email analogy above, the bridge is allowed to decide if the message should continue on. It reads the address bob@smith.com and decides if there is a bob@smith.com on the other side. If there isn’t, the message will not be transmitted.
- Bridges are typically used to separate parts of a network that do not need to communicate regularly, but still need to be connected.
Bridges are used to extend networks by maintaining signals and traffic.
OSI: Bridges are on the data link layer so in principle they are capable to do what switches do like data filtering and separating the collision domain, but they are less advanced. They are known to be used to extend distance capabilities of networks.
In a comparison with switches, they are slower because they use software to perform switching. They do not control broadcast domains and usually come with less number of ports.
OSI: Bridges are on the data link layer so in principle they are capable to do what switches do like data filtering and separating the collision domain, but they are less advanced. They are known to be used to extend distance capabilities of networks.
In a comparison with switches, they are slower because they use software to perform switching. They do not control broadcast domains and usually come with less number of ports.
Thursday, June 17, 2010
Factorial
#include<stdio.h> main() { int num,i; long int fact; clrscr(); printf("Enter a No. for finding factorial\n"); scanf("%d",&num); if(num<0) { printf("\n%d Factorial Not Defined.\n",num); } else { fact=1; for(i=1;i<=num;i++) { fact=fact*i; } printf("\n%d Factorial=%d\n",num,fact); } }
Output------>
Swapping of Two No.
#include<stdio.h> main() { int a,b,temp; clrscr(); printf("Enter Two No.: "); scanf("%d %d",&a,&b); printf("\nEntered No. are: "); printf("%d %d",a,b); temp=a; a=b; b=temp; printf("\n\nSwapped No. are: "); printf("%d %d",a,b); }Output-------->
Armstrong Number
#include<stdio.h>; main() { int num,n,sum,r; clrscr(); printf("Enter a Number for Armstrong Check\n\n"); scanf("%d",&num); n=num; sum=0; while(n!=0) { r=n%10; sum=sum+r*r*r; n=n/10; } if(sum==num) printf("\n %d is an Armstrong no. \n",num); else printf("\n %d is not an Armstrong No.\n",num); }
Output----->
Monday, June 7, 2010
Gopher
The Gopher protocol is a TCP/IP Application layer protocol designed for
-The protocol offers some features not natively supported by the Web and imposes a much stronger hierarchy on information stored on it.
-Its text menu interface is well-suited to computing environments that rely heavily on remote text-oriented computer terminals.
Its central Goals were:
-At a minimum, whatever a person can do with data files on a CD-ROM, they can do on Gopher.
-A Gopher system consists of a series of hierarchical hyperlinkable menus. The choice of menu items and titles is controlled by the administrator of the server.
-File on a Web server, a file on a Gopher server can be linked to as a menu item from any other Gopher server. Many servers take advantage of this inter-server linking to provide a directory of other servers that the user can access.
Veronica offers a keyword search of all the public Internet Gopher server menu titles.
A Veronica search produces a menu of Gopher items, each of which is a direct pointer to a Gopher data source.
- distributing,
- searching, and
- retrieving documents
-The protocol offers some features not natively supported by the Web and imposes a much stronger hierarchy on information stored on it.
-Its text menu interface is well-suited to computing environments that rely heavily on remote text-oriented computer terminals.
Its central Goals were:
- A file-like hierarchical arrangement that would be familiar to users
- A simple syntax
- A system that can be created quickly and inexpensively
- Extending the file system metaphor to include things like searches.
Gopher characteristics
-Gopher functions and appears much like a mountable read-only global network file system (and software, such as gopherfs, is available that can actually mount a Gopher server as a FUSE resource).-At a minimum, whatever a person can do with data files on a CD-ROM, they can do on Gopher.
-A Gopher system consists of a series of hierarchical hyperlinkable menus. The choice of menu items and titles is controlled by the administrator of the server.
-File on a Web server, a file on a Gopher server can be linked to as a menu item from any other Gopher server. Many servers take advantage of this inter-server linking to provide a directory of other servers that the user can access.
Related technology
The master Gopherspace search engine is Veronica.Veronica offers a keyword search of all the public Internet Gopher server menu titles.
A Veronica search produces a menu of Gopher items, each of which is a direct pointer to a Gopher data source.
Lynx
Lynx is a text-only Web browser for use on cursor-addressable character cell terminals.
-It is released as Free software under the GNU General Public License.
-Supported protocols are
-Lynx cannot inherently display various types of non-text content on the web, such as images and video, but it can launch external programs to handle it, such as an image viewer or a video player.
-Lynx is also used to check for usability of websites in older browsers.
-It is also useful for accessing websites from a remotely connected system in which no graphical display is available.
-Despite its text-only nature and age, it can still be used to effectively browse much of the modern web, including performing interactive tasks such as editing Wikipedia.
-The speed benefits of text-only browsing are most apparent when using low bandwidth internet connections, or older computer hardware that may be slow to render image-heavy content.
-Versions are also available for DOS, recent versions run on all Microsoft Windows releases, and Mac OS X.
-There was also an early port to "Classic" Macintosh version called MacLynx "for System 7 and later".
-Ports to BeOS, MINIX, QNX, AmigaOS and OS/2 are also available.
-It is released as Free software under the GNU General Public License.
-Supported protocols are
- Gopher,
- HTTP,
- HTTPS,
- FTP,
- WAIS, and
- NNTP.
Usage
-Browsing in Lynx consists of highlighting the chosen link using cursor keys, or having all links on a page numbered and entering the chosen link's number. Current versions support SSL and many HTML features.-Lynx cannot inherently display various types of non-text content on the web, such as images and video, but it can launch external programs to handle it, such as an image viewer or a video player.
-Lynx is also used to check for usability of websites in older browsers.
-It is also useful for accessing websites from a remotely connected system in which no graphical display is available.
-Despite its text-only nature and age, it can still be used to effectively browse much of the modern web, including performing interactive tasks such as editing Wikipedia.
-The speed benefits of text-only browsing are most apparent when using low bandwidth internet connections, or older computer hardware that may be slow to render image-heavy content.
Platforms
-Lynx was originally designed for Unix and VMS and is a popular console browser on Linux.-Versions are also available for DOS, recent versions run on all Microsoft Windows releases, and Mac OS X.
-There was also an early port to "Classic" Macintosh version called MacLynx "for System 7 and later".
-Ports to BeOS, MINIX, QNX, AmigaOS and OS/2 are also available.
Mosaic
Mosaic is the web browser credited with popularizing the World Wide Web. It was also a client for earlier protocols such as FTP, Usenet, and Gopher.
Its clean, easily understood user interface, reliability, Windows port and simple installation all contributed to making it the application that opened up the Web to the general public.
Mosaic was also the first browser to display images inline with text instead of displaying images in a separate window. While often described as the first graphical web browser, Mosaic was preceded by the lesser-known Erwise and ViolaWWW.
Its clean, easily understood user interface, reliability, Windows port and simple installation all contributed to making it the application that opened up the Web to the general public.
Mosaic was also the first browser to display images inline with text instead of displaying images in a separate window. While often described as the first graphical web browser, Mosaic was preceded by the lesser-known Erwise and ViolaWWW.
Saturday, June 5, 2010
WLAN
WLAN, which stands for Wireless Local Area Network, is the technology of networking of a number of computers with each other without requiring the usage of wires. Due to a number of WLAN's advantages such as ease of installation, convenience, deployment, mobility, expandability, productivity and cost, the popularity of WLAN has increased among home users. Wireless access is now offered as a service, paid or sometimes free, to customers of public businesses such as coffee shops or shopping malls.
There are three types of WLANs.
The first, peer-to-peer (P2P), enables wireless devices to directly communicate with each other without requiring the involvement of central access points.
The second WLAN type, which is a bridge, connects networks of different types, such as a wireless network to a wired Ethernet network.
The third type is the wireless distribution system, where access points are used as repeaters in place of connecting all access points in a network using wires.
WLAN networking signals may be subject to interference and complex propagation effects like multipath or Ricidian fading. WLANs also tend to have a limited range, requiring repeaters or additional access points in order to achieve greater range. They also have a slow data transmission rate of 1 - 108 Mbps, compared to wired networks which can run at rates of 100 Mbps to several Gbps. The built-in congestion avoidance of Transmission Control Protocol (TCP) hindered the transmission speed of wireless networks.
Twisted pair
Twisted pair cabling is a type of networking hardware formed by twisting two copper wires together in order to minimize electromagnetic interference (EMI) from outside sources as well as crosstalk between the two wires. Twisted pair cables are commonly used among small and medium-sized data networks because they are cheaper in comparison to other network mediums like coaxial and fiber-optic cabling.
tion of twisting two wires together was developed soon after the invention of the telephone in the 1870's. When open wire lines were used for transmission, the large loop area between the two wires caused them to receive a lot of EMI from the power lines that they were strung on.
Crosstalk also occurred, because the signals transmitted on each line caused an undesired effect or "noise" on the adjacent line. With greater loop area, the interference increased, thus limiting the length of the wires used. Engineers discovered that crossing the lines over each other once every several poles reduced the loop area, in effect reducing the crosstalk and EMI and allowing for greater wire lengths.
A typical twisted pair cable includes a number of pairs of copper wires twisted around each other. These twisted pairs are then twisted around other twisted pairs to form the whole cable.
Twist rate, usually measured in twists per meter, is a crucial aspect of cable installation. This factor determines how susceptible a cable is to EMI. For cables which have hundreds of pairs or more, the twist rate for each pair has to be specific.
Determining different twist rates for every pair would be difficult due to the quantity, so pairs are divided into smaller groups and assigned different twist rates. It is very important that the twisting remains intact during installation, so maximum pulling tension and minimum bend radius is required when devising the twisting schemes.
There are two main types of twisted pair cabling:
STP : Shielded Twisted Pair
UTP : Unshielded Twisted Pair
The difference between them being that UTP cables do not have any insulation or "shielding" surrounding them.
The lack of shielding in UTPs allows for greater flexibility and durability, and UTP cabling is the least expensive among all types of local area network (LAN) cables. Because of this, several Ethernet networks and telephone systems make use of UTP cables.
g provides greater protection against EMI, making STP the more ideal type of cabling for larger networks and businesses. In an STP cable, "shielding" refers to the metal wrapped around an individual twisted pair or wires.
"Screening" refers to the metal wrapped around the entire set of pairs. There are various combinations formed by the presence or absence of shielding and screening: STP, which has shielding but no screening; Screened Shielded Twisted Pair (S/STP), which has both shielding and screening and thus provides the best insulation from interference generated by outside sources; and Screened Unshielded Twisted Pair (S/UTP), which has screening but no shielding, basically making it a UTP with shielding. S/UTP may also be referred to as a Foiled Twisted Pair (FTP).
10BASE2
-10BASE2 (also known as cheapernet, thin Ethernet, thinnet, and thinwire) is a variant of Ethernet that uses thin coaxial cable, terminated with BNC connectors.
The Institute of Electrical and Electronics Engineers (IEEE) has assigned ThinNet the identifier 10BASE2, as a quick summary on the following characteristics of the standards:
- "10" means it has a maximum transmission speed of 10Mbps;
- "BASE" is shorthand for "baseband transmission" or "baseband Ethernet," meaning that the medium only transmits Ethernet signals; and
- "2" refers to its maximum network segment length of 185 meters, rounded up to 200 meters.
Aside from its maximum segment length, it is of note that there is also a minimum length for this standard. Cables must not be any shorter than 0.5 meters. Other restrictions for ThinNet include: no more than 30 devices may be attached to a single ThinNet port per segment or "daisy chain"; no more than 3 repeater devices may be used to connect two network devices; and a maximum of 5 connected segments are allowed.
BNC T-connectors are used to connect each cable segment to a Medium Attachment Unit (MAU), LAN card or transceiver, which is then connected to the computer. In terms of network topology, a ThinNet network is usually arranged in a bus configuration, meaning each computer station or node is attached to the cable segment, which is ended by a terminator on either side to prevent interference caused by a radio frequency signal from being reflected back from the end. RG-58 coaxial cables have a nominal impedance of 50 Ohms, so 50 Ohm terminators are required for termination at the physical end of a network.
It is important to assure that everything in a ThinNet network is properly installed and connected, because connection flaws at any point of the network cabling tend to prevent all communications, and it very difficult to diagnose bad contacts or shorts (although a time-domain reflectometer may aid in finding problems).
Wall-mounted EAD-sockets can, however, provide more reliable connections. In this aspect, 10BASE-T networks are preferable because they are easier to maintain, but ThinNet does have a number of advantages over 10BASE-T: it has cheaper hardware costs, and wiring is easier since only a single wire run is needed. Thus, ThinNet is more ideal for smaller networks, while 10BASE5 or 10BASE-T are preferable options for larger networks.
Among 10Mbps Ethernet standards, ThinNet was the most popular for several years, widely used for home desktop machines, but it has since been superseded by standards featuring the low-cost Category 5 cable, wireless local area network (WLAN) standards, and Ethernet standards featuring much faster transmission rates (i.e. 100Mbps or higher). In present-day computer networking, ThinNet is considered obsolete technology.
Network design
In a 10BASE2 network, each segment of cable is connected to the transceiver (which is usually built into the network adaptor) using a BNC T-connector, with one segment connected to each female connector of the T. At each physical end of the network a 50-ohm terminator is required. This is most commonly connected directly to the T-connector on a workstation though it does not technically have to be.
When wiring a 10BASE2 network, special care has to be taken to ensure that cables are properly connected to all T-connectors, and appropriate terminators are installed. One, and only one, terminator must be connected to ground via a ground wire. Bad contacts or shorts are especially difficult to diagnose, though a time-domain reflectometer will find most problems quickly. A failure at any point of the network cabling tends to prevent all communications.
10BASE5
10BASE5 (also known as thick ethernet or thicknet) is the original "full spec" variant of Ethernet cable, using cable similar to RG-8/U coaxial cable but with extra braided sheiding.
This is a stiff, 0.375-inch (9.5 mm) diameter cable with an impedance of 50 ohms (Ω), a solid center conductor, a foam insulating filler, a shielding braid, and an outer jacket.
ThickNet, also known as 10BASE5 or IEEE 802.3-1985, is an Ethernet standard that requires a specialized coaxial cable to transmit Ethernet frames at a rate of 10Mbps. It derives its nickname, which is a portmanteau of "Thick Ethernet," from the thick coaxial cable it uses, which is 0.375 inches in diameter.
The designation 10BASE5, assigned to the ThickNet standard by the Institute of Electrical and Electronics Engineers, provides a quick summary of the characteristics of its physical medium:
The designation 10BASE5, assigned to the ThickNet standard by the Institute of Electrical and Electronics Engineers, provides a quick summary of the characteristics of its physical medium:
"10" denotes its maximum data transmission rate of 10Mbps;
"BASE" is shorthand for "baseband transmission," meaning the medium exclusively transmits Ethernet signals; and
"5" means that it can transmit data at a maximum length of 500 meters before it experiences signal degradation.
The specialized coaxial cable used for a ThickNet computer network is sometimes referred to as "yellow cable" or "orange cable" because its outer insulation or jacket is made of either PVC (yellow) or Teflon (orange). This material makes the cable stiff and inflexible.
The cable contains a solid center conductor, and surrounding this conductor is an insulating filler made of foam, as well as a shielding braid. The cable must have a characteristic impedance of 50 ohms. Examples of coaxial cables made specifically for Ethernet include Belden numbers 9880 and 89880. ThickNet may also make use of RG-11 coaxial cable.
ThickNet employs a bus configuration as its network topology, meaning all nodes or devices are connected in a linear manner to one cable, known as a backbone, with 50 ohm resistive terminators at each physical end of the network. No more than 100 nodes may be connected to a ThickNet segment.
Transceivers, also known as Medium Attachment Units (MAU), were widely used in ThickNet networks. The term "transceiver" is a portmanteau of "transmiter" and "receiver," meaning it could both transmit and receive signals.
Transceivers were connected directly to cables through a device known as a "vampire tap," which is called such since it has spikes that pierce directly through the cable's outer jacket and into its center conductor. An N connector may also be used to connect a transceiver to a cable.
An Attachment Unit Interface (AUI) cable is used to connect a transceiver to a node. Transceivers may only be installed every 2.5 meters in order to not correspond to the wavelength of the signal. This minimizes echo and ensures that the reflections from multiple taps are not in phase.
ThickNet is the original Ethernet specification, although it was quickly superseded by 10BASE2 (also known as "ThinNet"). At present, it is considered obsolete computer networking technology.
Network design
The maximum practical number of nodes that can be connected to a 10BASE5 segment is limited to 100 and transceivers may be installed only at precise 2.5-metre intervals. This distance was chosen to not correspond to the wavelength of the signal; this ensures that the reflections from multiple taps are not in phase. These suitable points are marked on the cable with black bands. The cable must be one linear run; T-connections are not allowed. A 50-ohm resistive terminator is required at each end of the cable.
Transceivers can be connected to cable segments with N connectors, or via a vampire tap, which allows new nodes to be added while existing connections are live. A vampire tap clamps onto the cable, forcing a spike to pierce through the outer shielding to contact the inner conductor while other spikes bite into the outer braided shield.
Friday, June 4, 2010
Archie
On almost any subject, there are many sources of information around the Internet. Unfortunately, sometimes finding the location of the information that you want can be difficult. Archie can help you find things related to your topic of interest.
For example:
Invoking Archie.
The general method of use is of the form% archie stringThis will query the archie server for all known systems that have a file named string in their FTP area. Archie will wait, and print out any matches. For example,
% archie emacswill find all anonymous FTP sites in the archie database that have files named emacs somewhere in their FTP area. This example query would probably return many directories.
Archie Options.
If you want a list of files that contain emacs anywhere in the filename, you'd use the `c' option:% archie -c emacsThe most important options are:
-c Search substrings paying attention to upper & lower case. -e Exact string match. (This is the default.) -r Search using a regular expression. -s Search substrings ignoring the case of the letters. -t Sort the results inverted by date.A regular expressions, such as,
% archie -r '[xX][lL]isp'uses a matching template, in this case, matching xlisp, Xlisp, xLisp, and XLisp. If you list a single `-' by itself, any further arguments will be taken as part of the search string. This is intended to enable searching for strings that begin with a `-'.
For example:
% archie -s - -oldwill search for all filenames that contain the string `-old'.
TELNET
The Telnet Protocol The Telnet protocol is often thought of as simply providing a facility for remote logins to computer via the Internet. This was its original purpose although it can be used for many other purposes. It is best understood in the context of a user with a simple terminal using the local telnet program (known as the client program) to run a login session on a remote computer where his communications needs are handled by a telnet server program. It should be emphasised that the telnet server can pass on the data it has received from the client to many other types of process including a remote login server. It is described in RFC854 and was first published in 1983. Commands The telnet protocol also specifies various commands that control the method and various details of the interaction between the client and server. These commands are incorporated within the data stream. The commands are distinguished by the use of various characters with the most significant bit set. Commands are always introduced by a character with the decimal code 255 known as an Interpret as command (IAC) character. The complete set of special characters is | |||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||
There are a variety of options that can be negotiated between a telnet client and server using commands at any stage during the connection. They are described in detail in separate RFCs. The following are the most important. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||
Options are agreed by a process of negotiation which results in the client and server having a common view of various extra capabilities that affect the interchange and the operation of applications.Either end of a telnet dialogue can enable or disable an option either locally or remotely. The initiator sends a 3 byte command of the form IAC, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||
Associated with each of the these there are various possible responses | |||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||
For example if the sender wants the other end to suppress go-ahead it would send the byte sequence255(IAC),251(WILL),3The final byte of the three byte sequence identifies the required action.For some of the negotiable options values need to be communicated once support of the option has been agreed. This is done using sub-option negotiation. Values are communicated via an exchange of value query commands and responses in the following form. IAC,SB,,1,IAC,SEandIAC,SB,,0, For example if the client wishes to identify the terminal type to the server the following exchange might take place Client 255(IAC),251(WILL),24 Server 255(IAC),253(DO),24 Server 255(IAC),250(SB),24,1,255(IAC),240(SE) Client 255(IAC),250(SB),24,0,'V','T','2','2','0',255(IAC),240(SE) The first exchange establishes that terminal type (option number 24) will be handled, the server then enquires of the client what value it wishes to associate with the terminal type. The sequence SB,24,1 implies sub-option negotiation for option type 24, value required (1). The IAC,SE sequence indicates the end of this request. The repsonse IAC,SB,24,0,'V'... implies sub-option negotiation for option type 24, value supplied (0), the IAC,SE sequence indicates the end of the response (and the supplied value). |
PERL
Perl is a
-high-level,
-general-purpose,
-interpreted,
-dynamic
programming language. Perl was originally developed by Larry Wall in 1987.
Now, run it with your Perl interpreter. From a command line, go to the directory with this file and type
The
Numbers are easy; we've all dealt with them. The only thing you need to know is that you never insert commas or spaces into numbers in Perl. always write 10000, not 10,000 or 10 000.
Strings are a bit more complex. A string is a collection of characters in either single or double quotes:
Scalars are single things. This might be a number or a string. The name of a scalar begins with a dollar sign, such as
If you use a double-quoted string, Perl will insert the value of any scalar variables you name in the string. This is often used to fill in strings on the fly:
Numbers in Perl can be manipulated with the usual mathematical operations: addition, multiplication, division and subtraction. (Multiplication and division are indicated in Perl with the
Just remember, the plus sign adds numbers and the period puts strings together.
Arrays are lists of scalars. Array names begin with
Anything in a line of Perl code that follows a # sign is a comment. (Except, of course, if the # sign appears in a string.)
Perl has several different functions that are useful for flow control, the most basic of which is
A handy shortcut for defining loops is using
The single most complex line in the program is this one:
-high-level,
-general-purpose,
-interpreted,
-dynamic
programming language. Perl was originally developed by Larry Wall in 1987.
A Word About Operating Systems
In this series, I'm going to assume that you're using a Unix system and that your Perl interpreter is located at/usr/local/bin/perl
. It's OK if you're running Windows; most Perl code is platform-independent.Your First Perl Program
Take the following text and put it into a file calledfirst.pl
:#!/usr/local/bin/perl print "Hi there!\n";
(Traditionally, first programs are supposed to say
Hello world!
, but I'm an iconoclast.)Now, run it with your Perl interpreter. From a command line, go to the directory with this file and type
perl first.pl
. You should see:Hi there!
The
\n
indicates the ``newline'' character; without it, Perl doesn't skip to a new line of text on its own.Functions and Statements
Perl has a rich library of functions. They're the verbs of Perl, the commands that the interpreter runs. You can see a list of all the built-in functions on the perlfunc main page. Almost all functions can be given a list of parameters, which are separated by commas.The
print
function is one of the most frequently used parts of Perl. You use it to display things on the screen or to send information to a file (which we'll discuss in the next article). It takes a list of things to output as its parameters.print "This is a single statement."; print "Look, ", "a ", "list!";
A Perl program consists of statements, each of which ends with a semicolon. Statements don't need to be on separate lines; there may be multiple statements on one line or a single statement can be split across multiple lines.
print "This is "; print "two statements.\n"; print "But this ", "is only one statement.\n";
Numbers, Strings and Quotes
There are two basic data types in Perl: numbers and strings.Numbers are easy; we've all dealt with them. The only thing you need to know is that you never insert commas or spaces into numbers in Perl. always write 10000, not 10,000 or 10 000.
Strings are a bit more complex. A string is a collection of characters in either single or double quotes:
'This is a test.' "Hi there!\n"
The difference between single quotes and double quotes is that single quotes mean that their contents should be taken literally, while double quotes mean that their contents should be interpreted. For example, the character sequence
\n
is a newline character when it appears in a string with double quotes, but is literally the two characters, backslash and n
, when it appears in single quotes.print "This string\nshows up on two lines."; print 'This string \n shows up on only one.';
(Two other useful backslash sequences are
\t
to insert a tab character, and \\
to insert a backslash into a double-quoted string.)Variables
If functions are Perl's verbs, then variables are its nouns. Perl has three types of variables: scalars, arrays and hashes. Think of them as ``things,'' ``lists,'' and ``dictionaries.'' In Perl, all variable names are a punctuation character, a letter or underscore, and one or more alphanumeric characters or underscores.Scalars are single things. This might be a number or a string. The name of a scalar begins with a dollar sign, such as
$i
or $abacus
. You assign a value to a scalar by telling Perl what it equals, like so:$i = 5; $pie_flavor = 'apple'; $constitution1776 = "We the People, etc.";
You don't need to specify whether a scalar is a number or a string. It doesn't matter, because when Perl needs to treat a scalar as a string, it does; when it needs to treat it as a number, it does. The conversion happens automatically. (This is different from many other languages, where strings and numbers are two separate data types.)
If you use a double-quoted string, Perl will insert the value of any scalar variables you name in the string. This is often used to fill in strings on the fly:
$apple_count = 5; $count_report = "There are $apple_count apples."; print "The report is: $count_report\n";The final output from this code is
The report is: There are 5 apples.
.Numbers in Perl can be manipulated with the usual mathematical operations: addition, multiplication, division and subtraction. (Multiplication and division are indicated in Perl with the
*
and /
symbols, by the way.)$a = 5; $b = $a + 10; # $b is now equal to 15. $c = $b * 10; # $c is now equal to 150. $a = $a - 1; # $a is now 4, and algebra teachers are cringing.You can also use special operators like
++
, --
, +=
, -=
, /=
and *=
. These manipulate a scalar's value without needing two elements in an equation. Some people like them, some don't. I like the fact that they can make code clearer.$a = 5; $a++; # $a is now 6; we added 1 to it. $a += 10; # Now it's 16; we added 10. $a /= 2; # And divided it by 2, so it's 8.
Strings in Perl don't have quite as much flexibility. About the only basic operator that you can use on strings is concatenation, which is a $10 way of saying ``put together.'' The concatenation operator is the period. Concatenation and addition are two different things:
$a = "8"; # Note the quotes. $a is a string. $b = $a + "1"; # "1" is a string too. $c = $a . "1"; # But $b and $c have different values!
Remember that Perl converts strings to numbers transparently whenever it's needed, so to get the value of
$b
, the Perl interpreter converted the two strings "8"
and "1"
to numbers, then added them. The value of $b
is the number 9. However, $c
used concatenation, so its value is the string "81"
.Just remember, the plus sign adds numbers and the period puts strings together.
Arrays are lists of scalars. Array names begin with
@
. You define arrays by listing their contents in parentheses, separated by commas:@lotto_numbers = (1, 2, 3, 4, 5, 6); # Hey, it could happen. @months = ("July", "August", "September");
The contents of an array are indexed beginning with 0. (Why not 1? Because. It's a computer thing.) To retrieve the elements of an array, you replace the
@
sign with a $
sign, and follow that with the index position of the element you want. (It begins with a dollar sign because you're getting a scalar value.) You can also modify it in place, just like any other scalar.@months = ("July", "August", "September"); print $months[0]; # This prints "July". $months[2] = "Smarch"; # We just renamed September!
If an array doesn't exist, by the way, you'll create it when you try to assign a value to one of its elements.
$winter_months[0] = "December"; # This implicitly creates @winter_months.Arrays always return their contents in the same order; if you go through
@months
from beginning to end, no matter how many times you do it, you'll get back July
, August
and September
in that order. If you want to find the length of an array, use the value $#array_name
. This is one less than the number of elements in the array. If the array just doesn't exist or is empty, $#array_name
is -1. If you want to resize an array, just change the value of $#array_name
.@months = ("July", "August", "September"); print $#months; # This prints 2. $a1 = $#autumn_months; # We don't have an @autumn_months, so this is -1. $#months = 0; # Now @months only contains "July".
Hashes are called ``dictionaries'' in some programming languages, and that's what they are: a term and a definition, or in more correct language a key and a value. Each key in a hash has one and only one corresponding value. The name of a hash begins with a percentage sign, like
%parents
. You define hashes by comma-separated pairs of key and value, like so:%days_in_month = ( "July" => 31, "August" => 31, "September" => 30 );
You can fetch any value from a hash by referring to
$hashname{key}
, or modify it in place just like any other scalar.print $days_in_month{"September"}; # 30, of course. $days_in_month{"February"} = 29; # It's a leap year.
If you want to see what keys are in a hash, you can use the
keys
function with the name of the hash. This returns a list containing all of the keys in the hash. The list isn't always in the same order, though; while we could count on @months
to always return July
, August
, September
in that order, keys %days_in_summer
might return them in any order whatsoever.@month_list = keys %days_in_summer; # @month_list is now ('July', 'September', 'August') !
The three types of variables have three separate namespaces. That means that
$abacus
and @abacus
are two different variables, and $abacus[0]
(the first element of @abacus
) is not the same as $abacus{0}
(the value in abacus
that has the key 0
).Comments
Notice that in some of the code samples from the previous section, I've used code comments. These are useful for explaining what a particular piece of code does, and vital for any piece of code you plan to modify, enhance, fix, or just look at again. (That is to say, comments are vital for all code.)Anything in a line of Perl code that follows a # sign is a comment. (Except, of course, if the # sign appears in a string.)
print "Hello world!\n"; # That's more like it. # This entire line is a comment.
Loops
Almost every time you write a program, you'll need to use a loop. Loops allow you run a particular piece of code over and over again. This is part of a general concept in programming called flow control.Perl has several different functions that are useful for flow control, the most basic of which is
for
. When you use the for
function, you specify a variable that will be used for the loop index, and a list of values to loop over. Inside a pair of curly brackets, you put any code you want to run during the loop:for $i (1, 2, 3, 4, 5) { print "$i\n"; }
This loop prints the numbers 1 through 5, each on a separate line.
A handy shortcut for defining loops is using
..
to specify a range of numbers. You can write (1, 2, 3, 4, 5) as (1 .. 5). You can also use arrays and scalars in your loop list. Try this code and see what happens:@one_to_ten = (1 .. 10); $top_limit = 25; for $i (@one_to_ten, 15, 20 .. $top_limit) { print "$i\n"; }The items in your loop list don't have to be numbers; you can use strings just as easily. If the hash
%month
_has contains names of months and the number of days in each month, you can use the keys function to step through them.for $i (keys %month_has) { print "$i has $month_has{$i} days.\n"; }
for $marx ('Groucho', 'Harpo', 'Zeppo', 'Karl') { print "$marx is my favorite Marx brother.\n"; }
The Miracle of Compound Interest
You now know enough about Perl - variables, print, andfor()
- to write a small, useful program. Everyone loves money, so the first sample program is a compound-interest calculator. It will print a (somewhat) nicely formatted table showing the value of an investment over a number of years. (You can see the program at compound_interest.pl)The single most complex line in the program is this one:
$interest = int (($apr / 100) * $nest_egg * 100) / 100;
$apr / 100
is the interest rate, and ($apr / 100) * $nest_egg
is the amount of interest earned in one year. This line uses the int()
function, which returns the integer value of a scalar (its value after any fractional part has been stripped off). We use int()
here because when you multiply, for example, 10925 by 9.25%, the result is 1010.5625, which we must round off to 1010.56. To do this, we multiply by 100, yielding 101056.25, use int()
to throw away the leftover fraction, yielding 101056, and then divide by 100 again, so that the final result is 1010.56. Try stepping through this statement yourself to see just how we end up with the correct result, rounded to cents.
NFC
Near Field Communication or NFC, is a short-range high frequency wireless communication technology which enables the exchange of data between devices over about a 10 centimetre (around 4 inches) distance. The technology is a simple extension of the ISO/IEC 14443 proximity-card standard (proximity card, RFID) that combines the interface of a smartcard and a reader into a single device. An NFC device can communicate with both existing ISO/IEC 14443 smartcards and readers, as well as with other NFC devices, and is thereby compatible with existing contactless infrastructure already in use for public transportation and payment. NFC is primarily aimed at usage in mobile phones.
-The earlier advantage of NFC over Bluetooth with the shorter set-up time is still valid with standard Bluetooth protocol stack, but no more with Bluetooth V4.0 low energy protocol stack.
-With NFC, instead of performing manual configurations to identify devices, the connection between two NFC devices is established at once (faster than a tenth of a second).
-The maximum data transfer rate of NFC (424 kbit/s) is slower than Bluetooth V2.1 (2.1 Mbit/s). With less than 20 cm, NFC has a shorter range, which provides a limitation of threat. That mostly makes NFC suitable for crowded areas when correlating a signal with its transmitting physical device (and by extension, its user) becomes difficult.
NFC offers no protection against eavesdropping and is also vulnerable to data modifications. Applications have to use higher-layer cryptographic protocols (e.g., SSL) to establish a secure channel.
Unauthorized modification of data, which results in valid messages, is much more complicated and demands a thorough understanding. In order to modify the transmitted data an intruder has to deal with the single bits of the RF signal. The feasibility of this attack, i.e., if it is possible to change the value of a bit from 0 to 1 or the other way around, is amongst others subject to the strength of the amplitude modulation. If data is transferred with the modified Miller coding and a modulation of 100%, only certain bits can be modified. A modulation ratio of 100% makes it possible to eliminate a pause of the RF signal, but not to generate a pause where no pause has been. Thus, only a
Essential specifications
- Like ISO/IEC 14443, NFC communicates via magnetic field induction, where two loop antennas are located within each other's near field, effectively forming an air-core transformer. It operates within the globally available and unlicensed radio frequency ISM band of 13.56 MHz, with a bandwidth of 14 kHz.
- Working distance with compact standard antennas: up to 20 cm
- Supported data rates: 106, 212, 424 or 848 kbit/s
- There are two modes:
- Passive Communication Mode: The Initiator device provides a carrier field and the target device answers by modulating existing field. In this mode, the Target device may draw its operating power from the Initiator-provided electromagnetic field, thus making the Target device a transponder.
- Active Communication Mode: Both Initiator and Target device communicate by alternately generating their own field. A device deactivates its RF field while it is waiting.
- NFC devices are able to receive and transmit data at the same time. Thus, they can check the radio frequency field and detect a collision if the received signal does not match with the transmitted signal.
Uses and applications
NFC technology is currently mainly aimed at being used with mobile phones. There are three main use cases for NFC:- card emulation: the NFC device behaves like an existing contactless card
- Reader mode: the NFC device is active and read a passive RFID tag, for example for interactive advertising
- P2P mode: two NFC devices are communicating together and exchanging information.
- Mobile ticketing in public transport — an extension of the existing contactless infrastructure.
- Mobile payment — the device acts as a debit/ credit payment card.
- Smart poster — the mobile phone is used to read RFID tags on outdoor billboards in order to get info on the move.
- Bluetooth pairing — in the future pairing of Bluetooth 2.1 devices with NFC support will be as easy as bringing them close together and accepting the pairing. The process of activating Bluetooth on both sides, searching, waiting, pairing and authorization will be replaced by a simple "touch" of the mobile phones.
- Electronic ticketing — airline tickets, concert/event tickets, and others
- Electronic money
- Travel cards
- Identity documents
- Mobile commerce
- Electronic keys — car keys, house/office keys, hotel room keys, etc.
- NFC can be used to configure and initiate other wireless network connections such as Bluetooth, Wi-Fi or Ultra-wideband.
NFC vs Bluetooth
-NFC and Bluetooth are both short-range communication technologies which have recently been integrated into mobile phones. To avoid the complicated configuration process, NFC can be used for the set-up of wireless technologies, such as Bluetooth.-The earlier advantage of NFC over Bluetooth with the shorter set-up time is still valid with standard Bluetooth protocol stack, but no more with Bluetooth V4.0 low energy protocol stack.
-With NFC, instead of performing manual configurations to identify devices, the connection between two NFC devices is established at once (faster than a tenth of a second).
-The maximum data transfer rate of NFC (424 kbit/s) is slower than Bluetooth V2.1 (2.1 Mbit/s). With less than 20 cm, NFC has a shorter range, which provides a limitation of threat. That mostly makes NFC suitable for crowded areas when correlating a signal with its transmitting physical device (and by extension, its user) becomes difficult.
Security aspects
Although the communication range of NFC is limited to a few centimeters, NFC alone does not ensure secure communications. In 2006, Ernst Haselsteiner and Klemens Breitfuß described different possible types of attacks.NFC offers no protection against eavesdropping and is also vulnerable to data modifications. Applications have to use higher-layer cryptographic protocols (e.g., SSL) to establish a secure channel.
-Eavesdropping
The RF signal for the wireless data transfer can be picked up with antennas. The distance from which an attacker is able to eavesdrop the RF signal depends on numerous parameters, but is typically a small number of meters. Also, eavesdropping is extremely affected by the communication mode. A passive device, which does not generate its own RF field is much harder to eavesdrop on than an active device. An Open source device which is able to eavesdrop passive and active NFC communications is the Proxmark instrument.-Data modification
Data destruction is relatively easy to realize. One possibility to perturb the signal is the usage of an RFID jammer. There is no way to prevent such an attack, but if the NFC devices check the RF field while they are sending, it is possible to detect it.Unauthorized modification of data, which results in valid messages, is much more complicated and demands a thorough understanding. In order to modify the transmitted data an intruder has to deal with the single bits of the RF signal. The feasibility of this attack, i.e., if it is possible to change the value of a bit from 0 to 1 or the other way around, is amongst others subject to the strength of the amplitude modulation. If data is transferred with the modified Miller coding and a modulation of 100%, only certain bits can be modified. A modulation ratio of 100% makes it possible to eliminate a pause of the RF signal, but not to generate a pause where no pause has been. Thus, only a
1
which is followed by another 1
might be changed. Transmitting Manchester encoded data with a modulation ratio of 10% permits a modification attack on all bits.-Relay attack
Because NFC devices are usually also implementing ISO/IEC 14443 functionality, the relay attack described are also feasible on NFC. For this attack the adversary has to forward the request of the reader to the victim and relay back its answer to the reader in real time, in order to carry out a task pretending to be the owner of the victim’s smart card. One of libnfc code examples demonstrates a relay attack using only two stock commercial NFC devices.-Lost property
The very simple problem of losing the mobile phone and therewith opening access to any finder of the property is not addressed. Either the NFC RFID card or the mobile phone will act as single factor authenticating entities beyond the fact that the mobile phone is protected with the pin code again as a single authenticating factor. Hence the elementary aspect to defeat lost property threat requires an extended security concept including more than one physically independent authentication factors.-Walk off
Once lawfully opened access to secure function or data is usually protected with time out closing on pausing the usage. Modern attack concepts may interfere despite the intention to shut down access when the user turns inactive. The distance of a successful attacker to the locus of lawfully granted access is not addressed with any of the described concepts.NFC-enabled handsets
VRML
Virtual Reality Markup Language) is a standard file format for representing 3-dimensional (3D) interactive vector graphics, designed particularly with the World Wide Web in mind. It has been superseded by X3D.
-URLs can be associated with graphical components so that a web browser might fetch a webpage or a new VRML file from the Internet when the user clicks on the specific graphical component.
-Animations, sounds, lighting, and other aspects of the virtual world can interact with the user or may be triggered by external events such as timers. A special Script Node allows the addition of program code (e.g., written in Java or JavaScript (ECMAScript)) to a VRML file.
-VRML files are commonly called "worlds" and have the *.wrl extension (for example island.wrl). Although VRML worlds use a text format, they may often be compressed using gzip so that they transfer over the internet more quickly (some gzip compressed files use the *.wrz extension).
-Many 3D modelling programs can save objects and scenes in VRML format.
--------
VRML experimentation was primarily in education and research where an open specification is most valued. It has now been re-engineered as X3D. The MPEG-4 Interactive Profile (ISO/IEC 14496) was based on VRML (now on X3D), and X3D is largely backward-compatible with it. VRML is also widely used as a file format for interchange of 3D models, particularly from CAD systems.
A free cross-platform runtime implementation of VRML is available in OpenVRML. Its libraries can be used to add both VRML and X3D support to applications, and a GTK+ plugin is available to render VRML/X3D worlds in web browsers-------
Format
-VRML is a text file format where, e.g., vertices and edges for a 3D polygon can be specified along with the surface color, UV mapped textures, shininess, transparency, and so on.-URLs can be associated with graphical components so that a web browser might fetch a webpage or a new VRML file from the Internet when the user clicks on the specific graphical component.
-Animations, sounds, lighting, and other aspects of the virtual world can interact with the user or may be triggered by external events such as timers. A special Script Node allows the addition of program code (e.g., written in Java or JavaScript (ECMAScript)) to a VRML file.
-VRML files are commonly called "worlds" and have the *.wrl extension (for example island.wrl). Although VRML worlds use a text format, they may often be compressed using gzip so that they transfer over the internet more quickly (some gzip compressed files use the *.wrz extension).
-Many 3D modelling programs can save objects and scenes in VRML format.
Standardization
The Web3D Consortium has been formed to further the collective development of the format. VRML (and its successor, X3D), have been accepted as international standards by the International Organization for Standardization (ISO).--------
VRML experimentation was primarily in education and research where an open specification is most valued. It has now been re-engineered as X3D. The MPEG-4 Interactive Profile (ISO/IEC 14496) was based on VRML (now on X3D), and X3D is largely backward-compatible with it. VRML is also widely used as a file format for interchange of 3D models, particularly from CAD systems.
A free cross-platform runtime implementation of VRML is available in OpenVRML. Its libraries can be used to add both VRML and X3D support to applications, and a GTK+ plugin is available to render VRML/X3D worlds in web browsers-------
cookie
A cookie, also known as a web cookie, browser cookie, and HTTP cookie, is a text string stored by a user's web browser. A cookie consists of one or more name-value pairs containing bits of information, which may be encrypted for information privacy and data security purposes.
The cookie is sent as an HTTP header by a web server to a web browser and then sent back unchanged by the browser each time it accesses that server. A cookie can be used for authentication, session tracking (state maintenance), storing site preferences, shopping cart contents, the identifier for a server-based session, or anything else that can be accomplished through storing textual data.
As text, cookies are not executable. Because they are not executed, they cannot replicate themselves and are not viruses. However, due to the browser mechanism to set and read cookies, they can be used as spyware. Anti-spyware products may warn users about some cookies because cookies can be used to track people—a privacy concern.
Setting a cookie
Transfer of Web pages follows the HyperText Transfer Protocol (HTTP). Regardless of cookies, browsers request a page from web servers by sending them a usually short text called HTTP request. For example, to access the page http://www.example.org/index.html, browsers connect to the server www.example.org sending it a request that looks like the following one:
GET /index.html HTTP/1.1 Host: www.example.org | ||||
browser | | server |
The server replies by sending the requested page preceded by a similar packet of text, called 'HTTP response'. This packet may contain lines requesting the browser to store cookies:
HTTP/1.1 200 OK Content-type: text/html Set-Cookie: name=value (content of page) | ||
browser | | server |
The server sends the line
Set-Cookie
only if the server wishes the browser to store a cookie. Set-Cookie
is a request for the browser to store the string name=value
and send it back in all future requests to the server. If the browser supports cookies and cookies are enabled, every subsequent page request to the same server will include the cookie. For example, the browser requests the page http://www.example.org/spec.html by sending the server www.example.org a request like the following: GET /spec.html HTTP/1.1 Host: www.example.org Cookie: name=value Accept: */* | ||
browser | | server |
This is a request for another page from the same server, and differs from the first one above because it contains the string that the server has previously sent to the browser. This way, the server knows that this request is related to the previous one. The server answers by sending the requested page, possibly adding other cookies as well.
The value of a cookie can be modified by the server by sending a new
Set-Cookie: name=newvalue
line in response of a page request. The browser then replaces the old value with the new one.The term "cookie crumb" is sometimes used to refer to the name-value pair. This is not the same as breadcrumb web navigation, which is the technique of showing in each page the list of pages the user has previously visited; this technique, however, may be implemented using cookies.
The
Set-Cookie
line is typically not created by the base HTTP server but by a CGI program. The basic HTTP server facility (e.g. Apache) just sends the result of the program (a document preceded by the header containing the cookies) to the browser.Cookies can also be set by JavaScript or similar scripts running within the browser. In JavaScript, the object
document.cookie
is used for this purpose. For example, the instruction document.cookie = "temperature=20"
creates a cookie of name temperature
and value 20
.Cookie Basics
A cookie is a piece of text that a Web server can store on a user's hard disk. Cookies allow a Web site to store information on a user's machine and later retrieve it. The pieces of information are stored as name-value pairs.
For example, a Web site might generate a unique ID number for each visitor and store the ID number on each user's machine using a cookie file.
If you use Microsoft's Internet Explorer to browse the Web, you can see all of the cookies that are stored on your machine. The most common place for them to reside is in a directory called c:\windows\cookies. When I look in that directory on my machine, I find 165 files. Each file is a text file that contains name-value pairs, and there is one file for each Web site that has placed cookies on my machine.
You can see in the directory that each of these files is a simple, normal text file. You can see which Web site placed the file on your machine by looking at the file name (the information is also stored inside the file). You can open each file by clicking on it.
For example, I have visited goto.com, and the site has placed a cookie on my machine. The cookie file for goto.com contains the following information:
UserID A9A3BECE0563982D www.goto.com/
Goto.com has stored on my machine a single name-value pair. The name of the pair is UserID, and the value is A9A3BECE0563982D. The first time I visited goto.com, the site assigned me a unique ID value and stored it on my machine.
How does cookie data move?
As you saw in the previous section, cookie data is simply name-value pairs stored on your hard disk by a Web site. That is all cookie data is. The Web site stores the data, and later it receives it back. A Web site can only receive the data it has stored on your machine. It cannot look at any other cookie, nor anything else on your machine.
iStockphot
- If you type the URL of a Web site into your browser, your browser sends a request to the Web site for the page. For example, if you type the URL http://www.amazon.com into your browser, your browser will contact Amazon's server and request its home page.
- When the browser does this, it will look on your machine for a cookie file that Amazon has set. If it finds an Amazon cookie file, your browser will send all of the name-value pairs in the file to Amazon's server along with the URL. If it finds no cookie file, it will send no cookie data.
- Amazon's Web server receives the cookie data and the request for a page. If name-value pairs are received, Amazon can use them.
- If no name-value pairs are received, Amazon knows that you have not visited before. The server creates a new ID for you in Amazon's database and then sends name-value pairs to your machine in the header for the Web page it sends. Your machine stores the name-value pairs on your hard disk.
- The Web server can change name-value pairs or add new pairs whenever you visit the site and request a page.
There are other pieces of information that the server can send with the name-value pair. One of these is an expiration date. Another is a path (so that the site can associate different cookie values with different parts of the site).
You have control over this process. You can set an option in your browser so that the browser informs you every time a site sends name-value pairs to you. You can then accept or deny the values.
How do Web sites use cookies?
Cookies evolved because they solve a big problem for the people who implement Web sites. In the broadest sense, a cookie allows a site to store state information on your machine. This information lets a Web site remember what state your browser is in. An ID is one simple piece of state information -- if an ID exists on your machine, the site knows that you have visited before. The state is, "Your browser has visited the site at least one time," and the site knows your ID from that visit.
Web sites use cookies in many different ways. Here are some of the most common examples:
- Sites can accurately determine how many people actually visit the site. It turns out that because of proxy servers, caching, concentrators and so on, the only way for a site to accurately count visitors is to set a cookie with a unique ID for each visitor. Using cookies, sites can determine:
- How many visitors arrive
- How many are new versus repeat visitors
- How often a visitor has visited
- Sites can store user preferences so that the site can look different for each visitor (often referred to as customization). For example, if you visit msn.com, it offers you the ability to "change content/layout/color." It also allows you to enter your zip code and get customized weather information. When you enter your zip code, the following name-value pair gets added to MSN's cookie file:
WEAT CC=NC%5FRaleigh%2DDurham®ION= www.msn.com/
Since I live in Raleigh, N.C., this makes sense.
Most sites seem to store preferences like this in the site's database and store nothing but an ID as a cookie, but storing the actual values in name-value pairs is another way to do it (we'll discuss later why this approach has lost favor).
- E-commerce sites can implement things like shopping carts and "quick checkout" options. The cookie contains an ID and lets the site keep track of you as you add different things to your cart. Each item you add to your shopping cart is stored in the site's database along with your ID value. When you check out, the site knows what is in your cart by retrieving all of your selections from the database. It would be impossible to implement a convenient shopping mechanism without cookies or something like them.
In all of these examples, note that what the database is able to store is things you have selected from the site, pages you have viewed from the site, information you have given to the site in online forms, etc. All of the information is stored in the site's database, and in most cases, a cookie containing your unique ID is all that is stored on your computer.
Problems with Cookies
Cookies are not a perfect state mechanism, but they certainly make a lot of things possible that would be impossible otherwise. Here are several of the things that make cookies imperfect.
- People often share machines - Any machine that is used in a public area, and many machines used in an office environment or at home, are shared by multiple people. Let's say that you use a public machine (in a library, for example) to purchase something from an online store. The store will leave a cookie on the machine, and someone could later try to purchase something from the store using your account. Stores usually post large warnings about this problem, and that is why. Even so, mistakes can happen. For example, I had once used my wife's machine to purchase something from Amazon. Later, she visited Amazon and clicked the "one-click" button, not realizing that it really does allow the purchase of a book in exactly one click. On something like a Windows NT machine or a UNIX machine that uses accounts properly, this is not a problem. The accounts separate all of the users' cookies. Accounts are much more relaxed in other operating systems, and it is a problem.
If you try the example above on a public machine, and if other people using the machine have visited HowStuffWorks, then the history URL may show a very long list of files.
- Cookies get erased - If you have a problem with your browser and call tech support, probably the first thing that tech support will ask you to do is to erase all of the temporary Internet files on your machine. When you do that, you lose all of your cookie files. Now when you visit a site again, that site will think you are a new user and assign you a new cookie. This tends to skew the site's record of new versus return visitors, and it also can make it hard for you to recover previously stored preferences. This is why sites ask you to register in some cases -- if you register with a user name and a password, you can log in, even if you lose your cookie file, and restore your preferences. If preference values are stored directly on the machine (as in the MSN weather example above), then recovery is impossible. That is why many sites now store all user information in a central database and store only an ID value on the user's machine. If you erase your cookie file for HowStuffWorks and then revisit the history URL in the previous section, you will find that HowStuffWorks has no history for you. The site has to create a new ID and cookie file for you, and that new ID has no data stored against it in the database. (Also note that the HowStuffWorks Registration System allows you to reset your history list whenever you like.)
- Multiple machines - People often use more than one machine during the day. For example, I have a machine in the office, a machine at home and a laptop for the road. Unless the site is specifically engineered to solve the problem, I will have three unique cookie files on all three machines. Any site that I visit from all three machines will track me as three separate users. It can be annoying to set preferences three times. Again, a site that allows registration and stores preferences centrally may make it easy for me to have the same account on three machines, but the site developers must plan for this when designing the site. If you visit the history URL demonstrated in the previous section from one machine and then try it again from another, you will find that your history lists are different. This is because the server created two IDs for you, one on each machine.
There are probably not any easy solutions to these problems, except asking users to register and storing everything in a central database.
When you register with the HowStuffWorks registration system, the problem is solved in the following way: The site remembers your cookie value and stores it with your registration information. If you take the time to log in from any other machine (or a machine that has lost its cookie files), then the server will modify the cookie file on that machine to contain the ID associated with your registration information. You can therefore have multiple machines with the same ID value.
Subscribe to:
Posts (Atom)