C # Network Programming Study Note 1

Source: Internet
Author: User
What is TCP/IP?

A protocol group.
Why is TCP/IP popular?

Because it is compatible with various underlying networking and standards. (As the saying goes, there are various wiring methods and cables)
TCP/IP Layer

Application Layer: smtp ftp Telnet
Transport Layer: tcp udp (responsible for transmission and guaranteed arrival)
Network Layer: IP (responsible for defining house numbers and paths)
Data interfaces: Ethernet and Serial Line (closest to the physical layer, used to encapsulate the physical layer)

==================================
Socket classification (Transport Layer)

1. Stream corresponds to TCP protocol
2. Gram corresponds to UDP protocol
Socket Application:

When high-level protocols (such as HTTP and SMTP protocols) cannot meet your needs, it is strongly necessary to customize network transmission. Otherwise, you can use the webrequest, email, and FTP class libraries.
What is socket?

It can be seen as a data channel from the client to the server.
Socket class library

Tcpclient, tcplistener
Network services implemented using Socket

Telnet HTTP email echo
Usage -- similar to calling
Client:

1. Create a socket instance (new)
2. Connect to the specified server using the connet Method
3. Send data using the send or sendto Method
4. Receive receipt data through the receive or receivefrom Method
Server:

1. Bind the method to the specified port
2. Listen for requests using the listen Method
3. Receive client socket through accept
4. Process Data
5. Shutdown and close socket

Used classes:
Endpoint class:

Represents a terminal, generally expressed by address + port. The subclass ipendpoint is expressed by IP + Port
Obtain ipendpoint: ipendpoint ipep = new ipendpoint (IPaddress, Port );
IPaddress class:

Obtaining method: IPaddress myip = IPaddress. parse ("192.168.0.1 ");
DNS class:

Domain Name Service class. (Domain Name Service: a service that resolves www.fltek.com.cn as an IP address)
Iphostentry myhost = DNS. Resolve ("www.fltek.com.cn ");
(Or iphostentry myhost = DNS. gethostbyname ("www.fltek.com.cn ");)
IPaddress myip = myhost. Addresslist [0]; this obtains the above IPaddress

Common exceptions:

Socketexception
An error occurred while setting the argumentexception parameter.
Objectdisaposedexception socekt has disabled the exception

Note:
Synchronous and asynchronous:

synchronization means that the control is not handed over to the Program after the socket has not obtained the data, and the data is always retrieved. asynchronous data can be handed back to the program immediately.
example:
synchronous send method
asynchronous: beginsend

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.