How messages flows between computers connected with Internet or LAN?
I have been doing Windows programming in .Net since last two years. Now I am shifting to web programming so I just s开发者_StackOverflowtuck in understanding the fundamentals of web programming, after googling I came to StackOverflow to learn from all of you great guys.
My confusion is about how messages flow between systems in distributed enviornment ?
I mean suppose I want to send a message "Hello"
to a system connected to LAN or Internet,
then what will be the steps taken to send the message.
Second thing is suppose my system is "A"
and I wana send message to system "B"
which is connected via a wire, so how the message flows on wire and how system "B"
reads it from the wire ?
Please someone explain me in a layman terms.
Thank you all in advance.
Here's the short layman explanation of what is happening. you can search for any highlighted term to read more about the particular layer in the whole stack.
- Your browser creates an
HTTP
packet containing the GET request details for the page it needs. - It then asks the OS networking stack to deliver that packet over the
TCP/IP
protocol to the target machine. - If the browser gave the network stack the
domain name
(ie, http://google.com), the network stack makes a request to itsDNS
server to resolve that domain name to anIP address
(ie, 74.125.155.99).
The DNS server might need to contact other DNS servers, if it doesn't have that info cached locally. - Once the DNS server has determined the IP address and returned it to the OS networking stack, or if the HTTP request is addressed to an IP address directly, the networking stack will create a TCP/IP packet for that IP address and give it to the network card driver.
- The network card driver will wrap the TCP/IP packet in an
Ethernet frame
packet. - If the IP address is on the local network, the network card driver will try to determine what's the target machine
MAC address
in theARP table
. If it succeeds, then it will send the Ethernet frame packet over the network wire directly addressed to the MAC address of that machine. - If the IP address is not on the local network, the network card will send the Ethernet frame packet to MAC address of the local network gateway machine.
- The network card driver on the gateway machine will unwrap the TCP/IP packet and hand it off to that machine TCP/IP stack.
- The gateway machine TCP/IP stack will look at the destination IP address and repeat the proper steps above to deliver the packet to the target machine or the next machine in the route.
Basically it is not the computers that exchange messages, but the programs on these computers. So you need to have two programs or a single program but having instances running on both machines. Now here comes into play what people call sockets. You will need a detailed read and a basic code example on socket programming anyway, so I will just tell you the basics. A socket is a network abstraction. It is a thing thru which the programs on different computers communicate. You establish connection using sockets. And then basically sockets can be treated (almost) like files. You write bytes (your message) to a socket, and on the other end you receive your message thru a socket there. This is just a basic idea, your next step is to find a good example of socket programming in your desired language
There are several ways you can achieve that on the web. The easiest way I think you could do it is using ASP.NET Web Services.
But you should take a look at WCF, wich has becoming the pattern for thinks like that in MS world for the last years. Using WCF allows you to use a lot of different protocols just changing a xml configuration file.
HTTP over TCP/IP is what web services use. Most communications use TCP/IP with a protocol over it.
You can find a quick TCP/IP tutorial here and a more detailed one here
精彩评论