Site hosted by Angelfire.com: Build your free website today!
HTTP Protocol and Methods - Socket help document
- HTTP concept and protocol
- HTTP methods on headers
- HTTP server's replies
-HTTP socket Exemple
:
: by bar h.
: :


- Concept of sockets

A socket is a certain connection of data, A connection between two peers or a server
to create a connection. There are two types of known connections by mIRC, the TCP protocol
and the UDP. A simple TCP connection is what were using on usuall Applications, like
mIRC and Internet Explorer. the UDP protocol is based on Packets of data, which means
that handling should be known at first, Applications like ICQ, Kaaza, Napster (rip) uses
or used UDP before.

If you'd like to know more about Basic and general sockets, read the turorials on the
mircscripts.org's tutorials section.

As for any socket, There is a certain Protocol and common methods for general use of the
socket. As an exemple mIRC has a protcol, ICQ has a protocol, and HTTP is a protocol which
i will focus on here.
While i'm explaining (or trying to) about this Protocol i'm assuming that you have a bit
of Exeprience in sockets, Events and identifers.


- HTTP (Hyper Text Transfer Protocol)

Far as users know the HTTP protocol, is thorugh Internet Explorer, Netscape and maybe
Telnet, Here's a qoute from RFC 2616:

The Hypertext Transfer Protocol (HTTP) is an application-level
protocol for distributed, collaborative, hypermedia information
systems. HTTP has been in use by the World-Wide Web global
information initiative since 1990. The first version of HTTP,
referred to as HTTP/0.9, was a simple protocol for raw data transfer
across the Internet.


So basically, we send Data to server, Server sends us data back. pisa cake?
In order the server will understend our requests, a certain kind of data or any other
detail we must provide the server exectly what, Here are the common methods:




- Methods

GET webpatch/file [HTTP/1.x]

The GET request tells the server that what file do we want and in what Directory
is it located, usally the GET command it used for html files and binary files.
--
The HTTP/1.x (x as number, mustly 0), tells the server we want a HEADER first.
The HEADER contains the CODE of the event (OK, FILE MOVED, FILE NOT FOUND, NOT
AN AUTHORIZED REQUEST and so on), The file size (if it was found), server's local
time, VIA data, and fianlly a CRLF signal that means the file is now being sent.
The HEADER can contain Cookies, Authorzation requests, Relocations for the Explorer
to know the file has been Moved, but thats another thing.

POST webpatch/file [HTTP/1.x]

Almust like the GET method, only this one is used with certain kinds of files like
CGI, PHP, ASP and other types that works with an engine or so, I'm not fully
aware of its basic conecpt, but me and many others uses it on those kinds of files.

HEAD webpatch/file

This one simply requests for the HEADER of the file, the server will not send the file
and will send nothing but it's header (read the fallowing methods)

Host: current host

This method tells the server its host, Its quite weird telling the server its own
address but some HTTP servers requeirs that method in every request.

Accept: acceptble files

This method a bit more complicated then the others, Although it could be shortcuted
into a simple */* signal. Must clients sends the longer one, that speceifes
html and text files, what is applicatable and whats not and types of images.

Connection: Keep-Alive/Close

According to RFC's, this method tells the server that we want the connection to
remain or to be closed right away.

in the end of every method we must specify a CRLF signal used with $crlf or with the -n
switch in the /sockwrite command


Basic Client to Server HEADER:

GET /path/filename.html HTTP/1.0
Host: server.com
Connection: Close
Accept: */*
$crlf

To see your HEADER, click here

Once we've told the server what we want, The data should be sent to us, We must be ready with
a SOCKREAD event to handle the data, I'd use for a begining to /echo it into a @window:

ON 1:SOCKREAD:http: {
if (!$window(@http)) window @http
sockread %data
aline @http %data
}

Ofcourse the HEADER should be sent in the SOCKOPEN event.




- Replies

If we've mentioned the HTTP/1.x signal we should be expecting a HEADER from the server (read
above for more information), This HEADER should look like that:

HTTP/1.0 200 OK
Age: 0
Date: Sat, 07 Dec 2002 19:58:52 GMT
Content-Length: 16894
Content-Type: text/html
Connection: keep-alive
Server: Apache/1.3.26 (Unix) (Technologue/Linux) mod_fastcgi/2.2.2 mod_ssl/2.8.9 OpenSSL/0.9.6
Last-Modified: Thu, 02 Sep 1999 02:20:44 GMT
Via: 1.1 prx-VLAN110-014 (NetCache NetApp/5.2.1R1D8)

After the HEADER (if you requested for it) the actuall file is being sent, Ready with the ON SOCKREAD event we save
the data into a file, a castum window or just echo it, If you've requested a Binary file you should use the &binary
type to save data and to write it to a file (/help /bwrite), but there is a catch!
If we've got the HEADER that is ASCII, which means a Binary file will contain ASCII code that will screw the file.
To avoid writing the HEADER to the file, make sure you save the HEADER into and the Binary part into
&sockread and into the actual file, use the CRLF singal that seperates the HEADER from the file.

If you'd like to know more about HEAERs (Client's or Server's) read RFC's about HTTP and its method and download
snippets about HTTP for you to know more about the protocol.



- So what can be done with that socket?

* Simply downloading:
Downloading data about updating your script
Downloading news from a news server
Getting entertaiment, like jokes and pictures
* A Web server hosted on your machine

Some Exemples:
/getmap, shows a map of a requested country

/httpserv, checks some host's HEADER
/nickpic, gets an irc user's picture from ircnick.com
Hmm.. its not like this page is REALLY copyrighted, just dont bullshit around with it
mail me