Network Programming Overview (i)

Source: Internet
Author: User
Tags file transfer protocol

1. Common programming models are used by the OSI and TCP/IP models.

2. The main concepts in the network: protocols, interfaces and services.

Protocol refers to the rules that the same layer needs to interact on different hosts, often with Tcp/ip,ipx/spx,netbeui and so on. LAN is mainly ipx/spx, Internet -based is the use of TCP/IP.

An interface is a convention that interacts between different adjacent layers on the same host (what services to provide and what actions need to be specified).

Service is to provide the upper layer with a certain demand function, can be divided into connection-oriented services and non-connected services. The connection service (based on the phone model ) needs to experience establishing a connection using a connection and releasing the connection, and the entire process passes data on an orderly network route (providing stability). A disconnected service ( postal model ) divides the data that needs to be sent into several parts and then takes the destination address and then sends it out to the destination address in order, requiring the package number that is received at the destination address to be re-assembled sequentially. (Reduce communication costs)

The 3.TCP/IP protocol is an Internet-based protocol and a standard method for packaging and addressing computer data. Mainly consists of the following 4 layers: network interface layer, Internet layer (IP), Transport Layer (TCP), Application layer (Smtp,dns,ftp,telnet).

The network interface layer mainly controls how the network hardware transmits the upper IP data (it manages many protocols for various network hardware)

The Internet layer is the key layer of the Entire Network , responsible for the basic packet and addressing (IP protocol), IP protocol According to the specific network environment in the network under the circumstances of the IP packet re-subcontracting into the format of the environment and then sent. The IP module on the receiving end combines each small block of data into a packet in sequence to transmit to the TCP or UDP module.

The transport layer realizes the data Transfer service of the peer entity (computer to computer) , and the IP data is split to ensure that it is received and whether it needs re-transmission. There are mainly TCP ( Transmission Control Protocol) and UDP (Datagram protocol ) 2 kinds of protocols, one is the connection-oriented one is a non-connected protocol. TCP and UDP check whether there is a loss in the order defined before the IP packet is received and whether it is necessary to continue to send the lost content.

The application layer is the communication protocol to the application , including all high-level protocols. such as the Virtual Terminal Protocol (Telnet) File Transfer Protocol (FTP) e-mail Protocol (SMTP) DNS domain Name System HTTP Hypertext Transfer Protocol.

4. The computer general 0~1023 is fixed to allocate the broken port, the 1024~65535 is the dynamic port may according to the customer to give the specific procedure.

5. Memory Knowledge points

IPAddress class:

IPAddress Newaddress1 = Ipaddress.parse ("192.168.1.1");
IPAddress Newaddress2 = ipaddress.loopback;//127.0.0.1
IPAddress NEWADDRESS3 = ipaddress.broadcast;//255.255.255.255
IPAddress NEWADDRESS4 = ipaddress.any;//0.0.0.0
IPAddress NEWADDRESS5 = ipaddress.none;//255.255.255.255
Iphostentry here= Dns.gethostentry (Dns.gethostname ());//Address encapsulation Object

DNS Class (Domain Name System):

Ipaddress[] address= dns.gethostaddresses ("ZB");//Gets the IP collection of the specified address or computer name
Iphostentry iphostentry= dns.gethostentry ("10.2.15.48");//Get Iphostentry by IP address, it wraps IP information, can be a remote IP address
String Hostname= dns.gethostname ();//Get the native name

Iphostentry class: Providing a container class for host address information

Iphostentry hostentry = dns.gethostentry ("www.baidu.com");
ipaddress[] IPAddress = hostentry.addresslist;
String Hostname= hostentry.hostname;

IPEndPoint class:

IPAddress newaddress = Ipaddress.parse ("192.168.1.1");
IPEndPoint EP = new IPEndPoint (newaddress, 8000);
AddressFamily addressfamily = EP. AddressFamily;
IPAddress epaddress = EP. Address;
String port = Ep. Port.tostring ();
SocketAddress sa = EP. Serialize ();//serialize to network address
String socketaddress = sa. ToString ();

Socket class:

Sockets derive tcpclient,tcplistener,udpclient they provide a direct way to operate the network, if the need for asynchronous operations requires the use of networkstream;

6. Socket: is actually a data channel handle. It consists of the Ip+ Transport Protocol (TCP or UDP) + port.

. NET provides 3 types of sockets: Streaming Sockets (stream is TCP), datagram sockets (that is, UDP), raw sockets (raw).

Socket socket;

Property:
Socket. Blocking = false;//If a blocking program is required
Socket. connected;//Current status
EndPoint rmendpoint= socket. remoteendpoint;//Remote End point
EndPoint lcendpoint = socket. localendpoint;//Local End point

Method:

Socket socket = new Socket ("Protocol family", "Transport type (UDP/TCP)", "Port Type"),//create socket, and return handle.

IPAddress ADDRESS3 = Ipaddress.parse ("192.168.1.1");

IPEndPoint EP2 = new IPEndPoint (ADDRESS3, 8000);
Socket. Bind (EP2);//Bind the created socket to the native IP and port
Socket. Listen (100);//indicates that the program is ready to start a listening request, where the parameter represents the maximum number of receive requests.
Socket. Accept ();///When a client connects to the server, a new socket is returned, and the program runs to the method that is blocked, knows that there is a client connection, and is typically placed in a loop
Socket. Connect ("endpoint");//This method is primarily used by the client, and is responsible for binding the created socket to the local address, corresponding to bind ()
Socket. Send (); Socket. Receive ();//transmit and receive data
Socket. Shutdown ();//Closing the communication release

Network Programming Overview (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.