Home > other >  What is a network programming
What is a network programming

Time:09-24

Transfer: http://peixun.eol.cn/company/company_article_detail.php? Articleid=15033

For beginners, or no contact with network programming, programmers will feel involved in network programming knowledge is profound, very difficult, in fact this is a misunderstanding, when your grammar is familiar with basic network programming is now actually be implemented quite simple,

Network programming is what?

Network programming is the nature of the data exchange between the two devices, of course, in computer network, the equipment is mainly refers to the computer, data transfer itself without much difficulty, is it not send data from a device to another device, then accept another equipment feedback data,

Now network programming basically all is based on the request/response mode, which is a device sends the request data to another, and then receive feedback of another equipment,

In network programming, a connector, also is the first time send request program, known as the Client (Client), waiting for the other program of the connection is referred to as a Server (Server), the Client program can be started in time of need, corresponding connection, the Server in order to be able to point you will need to have been started, such as to make a phone call, for example, the first dial is similar to the Client, answer the call of the people must keep clear of the telephone is similar to the Server,

Once the connection is established, the client and the server can perform data transfer, and the identity of the two are equivalent,

In some applications, the program has both function of client and server side function, one of the most common software is BT, emule such software,

Here to talk about how to establish a connection, and how to send data,

IP address and domain name

In real life, if you want to call you need to know the corresponding people's phone number, if you want to post the letter you need to know the address of the receiver, in the network also is such, need to know the position of a device, you need to use the IP address of the device, specific connection process by the hardware implementation, programmers don't need to care too much,

IP address is a regulation, is now using IPv4, both by four Numbers between 0-255, internally stored on a computer, you just need to four bytes in a computer, an IP address is assigned to the network card, each card has a unique IP address, if a computer has multiple network CARDS, the station has a number of different computer IP address, within the same network, IP address cannot be the same, the concept of IP address is similar to the phone number, id card concepts,

Because the IP address is not convenient to memory, so a specially created the concept of Domain Name (Domain Name), is a character Name for the IP, such as 163. com, sina.com, etc., there is a corresponding relationship between IP and Domain Name, if the IP address is likened to id number, then the Domain Name is your Name,

Actually can only be used in the network IP address data transmission, so before transmission, the need to convert the domain name to IP, dedicated to complete this by called DNS server,

So in network programming, you can use the IP or domain name to identify a device on the network,

The concept of port

To on one device can run multiple programs, people design the concept of Port (Port), a similar example is the company's internal extension number,

Provisions of a device with 216, 65536 ports and each port corresponding to a unique program, each program, both the client and the server side, all corresponding to one or more specific port number, as between 0 and 1024 more are occupied by the operating system, so the actual programming generally adopt the port after 1024, when

Use the port number, you can find the only a program on one device,

So if you need a connection is established and a computer, you just need to know the IP address or domain name, but if you want to exchange data with the station a program on your computer, must also know the program using the port number,

Data transmission way

Know how to establish a connection, the following is how to transmit data, first look at the data transmission way,

On the network, both wired and wireless transmission, data transmission in one of two ways:


Transmission control protocol (TCP), the transmission is a kind of stable and reliable transmission mode, is similar to the call display, only need to establish a connection, can transmit data for many times, like only need to dial a number, you can achieve has been on the phone, if you say not clear, the other side will require you to repeat, guarantee the reliable transmission of data,

The advantages of using the method is stable and reliable, the disadvantage is that connection is established and maintain a connection cost is high, the transmission speed,


User datagram protocol, the transmission way does not establish a stable connection, similar to the hair short message, every time send data directly to send, send texts, you need to input number, and a lot of times the transmission mode is not reliable, the data may not receive, system ensure that only try our best to send,

Using this method has the advantage of small overhead, transmission speed is fast, the disadvantage is that data can be lost,

In the actual network programming, you can choose any kind of transmission mode according to need, or use a combination of these two approaches, to realize the data transfer

The concept of agreement

Protocol (Protocol) is a very important concept in network programming, refers to the transmission of data format, because we need to transport all kinds of information in the network, in the program are given in a set of values, how to read these values, you need to advance good provisions of this set of data format, according to the format generated on the client to send data, according to the format to read the data on the server, and then according to certain format generated data feedback to the client, the client to read data in accordance with the format, in reality a similar example is the telegram coding, each number is expressed in specific data,

General procedure of the protocol are divided into the client sends data formats, and the server side feedback data format, client and server are all follow the format generated or processing data, realize the complex data exchange between the two,

Summary

Network programming is to use the IP address or domain name, and port to connect to another computer on the corresponding procedures, in accordance with the provisions of the agreement (data format) to exchange data, the connection is established in practical programming and sending, receiving data at the language level is implemented, do more work is to design protocols, and write code to parse and generate data, and then put data into a logical structure to display or control logic,

For beginners, or no contact with network programming, programmers will feel involved in network programming knowledge is profound, very difficult, in fact this is a misunderstanding, when your grammar is familiar with basic network programming is now actually be implemented quite simple,
  • Related