Re: How hard is socket programming?
Peter Olcott wrote:
I have heard of raw sockets. From what I understand, at this
level not all of the lower level is hidden here. What level
are raw sockets exactly?
Any data that is not processed is RAW. :)
You got raw sockets and raw packets. In OCI Model, raw packets can be
defined to be at the data link level 2, raw sockets at the IP
networking level 3.
Example, PING utilities use raw sockets.
Okay so I would be using the sockets library in TCP mode. I
am guessing that I could cut out a lot of the HTTP bandwidth
overhead by doing this, and have more control over the
connection.
I don't get you. You have no choice but to use TCP based sockets if
you want to do HTTP, FTP, SMTP, NNTP, IMAP, POP3, etc, programming.
Your "socket program" become "HTTP Program" only because of the
agreement between what data you will be sending and the remote server
will be receiving - the HTTP formatted data.
Your "socket program" become "SMTP (EMAIL) Program" only because of
the agreement between what data you will be sending and the remote
server will be receiving - the SMTP formatted data.
And so on and all cases, you have the same functions:
socket() - pick up your telephone
connect() - dial and answer
send() - TALK ENGLISH
recv() - HEAR ENGLISH
close() - hang up
what makes it HTTP, is what you send and receive() over the
connection. No more.
The simple example is sending two lines as one string:
CString s = ""
s += "GET /HOMEPAGE.HTM HTTP 1.1\r\n";
s += "HOST: peter.com\r\n";
s += "\r\n";
send(hsocket, s, strlen(s), 0);
Your web server, see the GET line, reads HOMEPAGE.HTM from the server
"root document" folder and dumps it out using the send() command itself.
Now you read what the server sent, using recv() in some loop:
char buffer[1024*8];
int len;
while ((int len =recv(hsocket,buffer,sizeof(buffer),0)> 0) {
// I'm a web browser, display the html
DisplayHTML(buffer, len);
}
Thats it! Its all SOCKETS!
--
HLS