C#.net synchronous asynchronous socket communication and multithreading summary

Source: Internet
Author: User
Tags socket client

Synchronous Socket Communication

On-line point-to-point communication supported by socket

The service side realizes the listening connection, the client realizes sends the connection request, establishes the connection to send and receives the data the function

Server side to establish a socket, set up the IP and listening to the port and socket to bind, start listening to the connection request, when the connection request, send confirmation, establish a connection with the client, start communication with the client.

The client establishes a socket, sets the server-side IP and the service port, issues the connection request, receives the service confirmation, tries to connect, starts to communicate with the server.

Server-side and client connections and data transfer between them are synchronized.

Socket

The socket is a TCP\IP network protocol interface. Many functions and routines are defined internally. Can be viewed as an endpoint of network communication. Two hosts or two processes are required in network communications. Data is passed over the network, and the program needs a socket at each end of the network conversation.

The TCP/IP transport layer uses the protocol port to transfer data to a specific application of a host, which is the process address of an application. The network software module of the Transport layer module wants to communicate with another program, it will use the protocol port, the socket is the API running at the transport layer, use the socket to establish the connection to send the data to specify a port to it.

Socket:

Stream socket sockets Stream socket socket provides bidirectional, orderly, no duplication of data flow services, out of a large number of network data.

Dgram socket Packet sockets support bidirectional data flow, which does not guarantee the reliability, order and repetition of the transmission.

Row socket RAW socket access underlying protocol

Create socket with C #

Namespaces: Using system.net;using System.Net.Socket;

To construct a new socket object: Socket prototype:

Public socket (addressfamily addressfamily,sockettype sockettype,protocoltype protocoltype)

AddressFamily is used to specify the addressing scheme for the socket resolution address. Inte.network requires IP version 4 address, INTE.NETWORKV6 need IP version 6 address

The SocketType parameter specifies that the socket type RAW supports base transport protocol access, stream supports reliable, bidirectional, and based on connected data streams.

ProtocolType represents the network protocol supported by the socket

To define a host object:

IPEndPoint class: IPEndPoint Construction method Location: System.Net

Prototype:

1) Public IPEndPoint (IPAddress Address,int Port)

2 Public IPEndPoint (long address,int port) Parameter 1 integral type int64 such as 123456, Parameter 2 port int32

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.