• Please review our updated Terms and Rules here

questons on networking

yiu

New Member
Joined
Aug 3, 2004
Messages
3
I'm not sure if it is the right place to post this question...

I would like to understand the mechanism on how data is transfer in network..(in details)

suppose I've written a software program that get data from network (html pages , programs or another machines...)

and...how does the computer get the data and then write it back to the program?? how the microprocessor work?? what's the format of the data gathered from the network??

the questions I asked maybe too general to answer (I'm sorry about that) but all I have in my mind are blank and question marks...


anyone please help~

thx for your attention!
 
The questions you have could fill an entire book. In fact, they have, many times. I'd suggest picking up one of the many good books written on the subject. A good place to start is Networking For Dummies, available at any bookstore or perhaps your local library. Good luck.

--T
 
Networking is always (?) computer to computer (for many values of "computer", i.e. a network printer, firewalls, webcams etc). Networking consists of several layers: physical layer, network layer, data layer, application layer and so on. Different kinds of network traffic are divided into stacks, protocols and subprotocols. Each piece of equipment should have its unique identification number (MAC) and for IP networks also an IP number. Subprotocols in e.g. TCP/IP work on different so-called ports to differ them.

A HTML document itself never transmits any network traffic. It is a web server in one end sending the document to the client in the other end. The subprotocol used in this specific case is called http.

In order to make a program which hooks onto the network, you normally want an operating system and development tools which have network support, plus of course the hardware (network card, modem, serial cable etc) to connect to something. A little depending on the computer, your program normally opens a "socket" where it specifies which kind of network traffic it wants to connect to.

As a way to end this rather unspecific message, here is some code I would use if I wrote a web browser. It is written in the C language and should compile on Solaris (Unix) - I think Windows does something similar?

Caveat emptor - there may be fatal bugs and things missing here. It should NOT be taken as a working application but rather as an example of program flow. Or maybe not even that, there might be better and more modern ways to do it...

Code:
/* Simple socket example. Libs required: -lnsl -lsocket */

#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>
#include <fcntl.h>
#include <stdio.h>

int readln(int sock, char *buf) {
  int i=0,err=0,quit=0;
  do {
      err=read(sock,buf,1);
      if (err>=0 && *buf!='\n') {
          if (*buf=='\015') *buf='\0';
          i++;
          buf++;
        }
      else quit=1;
    } while (quit==0);
  *buf='\0';
  return i;
}

int main(int argc, char **argv) {
  FILE *comm;

  unsigned int mysock;
  int myport;
  struct hostent *myhost;
  union {
    struct sockaddr adr;
    struct sockaddr_in in;
  } myadr;

  int flag,i,from,to,qp=0,cmpl=0;
  index *db=NULL,*tmp,*itmp;
  message *first,*mtmp,*tmp2;

  char *buff,*subj,line[10000],ut[1000],user[20];

  /* This stupid web browser is hard-coded to the best website :-) */
  myhost=gethostbyname("www.vintage-computer.com");
  myport=80;

  myadr.in.sin_port=htons((unsigned short) myport);
  myadr.in.sin_addr.s_addr=*(unsigned long *)myhost->h_addr_list[0];
  myadr.in.sin_family = AF_INET;
  if ((mysock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1)  
     perror("Unable to open socket");  /* Open socket */
  if (connect(mysock, &myadr.adr, sizeof(myadr))==-1)  
     perror("Unable to connect");  /* Connect socket */

  if (fcntl(mysock,F_SETFL,O_NONBLOCK)==-1)
    perror("Unable to set non-blocking data stream");

  /* Make HTTP request to get starting page - old HTTP standard */
  sprintf(line,"GET / HTTP/1.0\n");
  write(mysock, line, strlen(line));

  flag=0;
  while (readln(mysock,ut)==0) {
    printf ("%s\n",ut);  /* output the HTML document onto screen */
  }

   if (shutdown(mysock,2))      
    perror("Unable to shutdown socket"); /* shut down socket ... */

  if (close(mysock))
   perror("Unable to close socket");

  exit(0);
}
 
thanks

thanks

thanks for all of you~

I know it's a large topic that involves many parts of computer...
and I have to study it step by step..

your posts do help me understand more about it and where to get more info

really thx !
 
Yep, might as well start with the fundamentals, like the OSI 7-layer protocol:
Definitions of OSI Model on the Web:

The Open Systems Interconnection (OSI) reference model for describing network protocols was devised by the Internet Standards Organization. It divides protocols in to seven layers to standardize and simplify definitions. To the Top
www.ircbeginner.com/opvinfo/webglossary.html


The Open Systems Interconnection (OSI) reference model for describing network protocols was devised by the Internet Standards Organization. It divides protocols in to seven layers to standardize and simplify definitions.
csu.colstate.edu/webdevelop/glossary.htm


The International Organization for Standardization Reference model for Open Systems Interconnection. A proposed international standard for network architecture that defines a seven-layer model, specifying services and protocols for each layer.
www.rad.com/networks/1994/transmis/glossary.htm


abbr. Open Systems Interconnection Model
education.icn.siemens.com/doc/jobaids/glossary/test_O.htm


The Open Systems Interconnection (OSI) reference model for describing network protocols was devised by the Internet Standards Organization. It divides protocols in to seven layers to standardize and simplify definitions. [Top of Page]
www.lib.uconn.edu/lib-assignments/webglossary.htm


Open Systems Interconnection; a protocol that represents a group of specific, successive tasks which enable computers to communicate with one another.
myphliputil.pearsoncmg.com/student/bp_jessup_ist_1/JessupGlossary.html


Divides the communication process into layers within which compatible standards can be set.
lms.thomsonelearning.com/hbcp/glossary/glossary.taf


Of all the standards to come out of the Open Systems Interconnect specifications, the OSI network model is the most common and enduring. The OSI model is a seven-layer view of looking at the network. It is presented below, with rough analogues from TCP/IP and Winsock.
www.coders.eu.org/manualy/win/wskfaq/glossary.html


a widely accepted standard of describing the network from the point of view of data flow. This model divides the protocols into 7 groups. To find out more, click here...
www.infonomics.nl/~gregu/brain/glossary.html


7-layer hierarchical reference structure developed by the International Standards Organization (OSI) for defining, specifying, and relating communications protocols; not a standard or a protocol; short for International Standard Reference Model of Open Systems Interconnection. Go back to top Return to prior location by pressing back button
www.libertycds.com/Voice/glossary.htm

That should give you some more ideas about what to look for, and where to look.

--T

EDIT: Several of the definitions above refer to the Internet Standards Organization, but I remember there being an OSI model long before there was an Internet or an Internet Standards Organization. It's been with us since the seventies, at least. (I have old books that mention it, but they're all in storage right now).

--T
 
"carlsson" wrote:

> As a way to end this rather unspecific message, here is
> some code I would use if I wrote a web browser. It is
> written in the C language and should compile on Solaris
> (Unix) - I think Windows does something similar?

Crikey Carlsson, that program looks really modern, do you
understand it?

I reckon that if you do, then you shouldn't limit yourself to
that, I reckon if you fully understand C, then you can fully
understand anything! ;-)

Cheers,
CP/M User.
 
In practise, I think the 7-layer OSI model is bypassed for a fewer layer abstraction, but the concept is the same.

Regarding the code snippet; yes, it is rather modern but I think a modern compiler on a vintage networked computer would swallow it rather well, in particular if that vintage computer uses the same networking primitives. Actually, more than half of that program I have written myself a few years ago. While some is magic (like how one integer variable can hold a whole connection), it explains itself after reading some man pages on the subject. Of course I "understand" and regularily use C as a language - it is not as hookey pookey as you may think. There are far more difficult things to grasp, like routing protocols or cryptology.
 
"carlsson" wrote:

> In practise, I think the 7-layer OSI model is bypassed
> for a fewer layer abstraction, but the concept is the
> same.

> Regarding the code snippet; yes, it is rather modern
> but I think a modern compiler on a vintage networked
> computer would swallow it rather well, in particular if
> that vintage computer uses the same networking
> primitives.

Actually, I'm not critizing the code, I just felt it's a bit
beyond me (I'm guessing it's C++? or just C built up?)
but someone once told me that if you could learn C,
then you could learn anything! :)

> Actually, more than half of that program I have written
> myself a few years ago. While some is magic (like how
> one integer variable can hold a whole connection), it
> explains itself after reading some man pages on the
> subject. Of course I "understand" and regularily use C
> as a language - it is not as hookey pookey as you may
> think. There are far more difficult things to grasp, like
> routing protocols or cryptology.

Well yeah, there's a level of difficulty to everything. I just
think that C is the building block & that if someone knows
C really well, then they -Could- archieve that concept.

I always remember having trouble with some of the
concepts of Boolean Algebra when I was learning about
computers, but there's various degrees, but all pretty
much work from the Truth Tables of Logic.

Cheers,
CP/M User.
 
Back
Top