C#. NET to realize socket communication __.net

Source: Internet
Author: User

1 Socket Communication Process

==> server-side listening: The server-side socket does not locate the specific client socket, but is waiting for the listening state, real-time monitoring network status.

==> Client Request: The client clientsocket send a connection request, the target is the server-side ServerSocket, so the client clientsocket must know the IP address and port number of the server-side ServerSocket. Used to perform a scan to send a connection request.

==> Connection Confirmation: When the server Socket monitor heard or received a client socket connection request, the server side of the corresponding client connection request, create a new socket, the server socket to send to the client, once the client confirms the connection, the connection is established. (Note: In the connection confirmation phase, the server-side socket even with the client socket connection, still in the listening state, still can accept the other client's connection request, that is, a server side can correspond to multiple clients).

2) Learning Socket class

==>socket Class Learning

Public Socket (addressfamily addressfamily,sockettype sockettype,protocoltype protocoltype);

(This is the create socket for the TCP protocol)

AddressFamily is the network type, generally using addressfamily.internetwork (IPV4);

SocketType represents the socket type, and TCP uses the SocketType.Stream;

ProtocolType represents the protocol used, and TCP uses PROTOCOLTYPE.TCP.

(This is the create socket for the UDP protocol)

AddressFamily is the network type, generally using addressfamily.internetwork (IPV4);

SocketType represents the socket type, UDP uses the Sockettype.dgram;

ProtocolType means the communication protocol used, UDP uses protocoltype.udp;

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.