Socket related Concepts

Source: Internet
Author: User

The English meaning of the lsocket is "hole" or "socket". As a process communication mechanism, take the latter meaning. Often also referred to as a "socket," which describes the IP address and port, is a handle to a communication chain. (In fact, it is two programs for communication purposes.) ) The lsocket is very similar to a telephone socket. Take a telephone network as an example. Phone calls are equivalent to each other 2 programs to communicate with each other, the phone number is an IP address. Any user before the call, the first to occupy a telephone, equivalent to apply for a socket, and to know the other person's number, the equivalent of the other side has a fixed socket. The call is then dialed to the other side, which is the equivalent of making a connection request. If the other party is present and free, pick up the telephone handset, both sides can formally call, the equivalent of a successful connection. The process of the two sides of the call is the direction of the telephone signal and the other side from the telephone to receive the signal, the equivalent of sending data to the socket and receiving data from the socket. After the call is over, one side hangs up the phone equivalent to closing the socket and undoing the connection. There are many such hosts on the internet, which typically run multiple service software while providing several services. Each service opens a socket and binds to a port, and the different ports correspond to different services (applications). L For example: HTTP uses 80 port FTP using 21 port SMTP 25 port L There are two types: • Streaming socket (stream):
is a connection-oriented socket, which is secure but inefficient for connection-oriented TCP service applications. • Datagram Socket (DATAGRAM):
is a non-connected socket that corresponds to a non-connected UDP service application. Unsafe (lost, sequential, on the receiving side to analyze reflow and require a re-send), but high efficiency. Socket general Application Mode (server side and client)

1. Server welcoming socket start listening port (responsible for listening for client connection information)
2. Client clients Socket connection server specified port (responsible for receiving and sending service-side messages)
3. Service-side welcoming socket monitor to hear the client connection, create connection socket. (responsible for communicating with clients)

L Server-side sockets (minimum two) • One is responsible for receiving client connection requests (but not responsible for communicating with clients) • Each successful receive client connection creates a corresponding socket on the service side that is responsible for the communication that is created when the client connection is received. A corresponding socket (responsible for communicating with the client) is created on the server for each successful client request.

The client's socket client socket must specify the server-side address and port to connect to.

Initializes a server-side TCP connection by creating a socket object

L Server-side: • Apply a socket bound to an IP address and a port • Turn on Listen, wait for the connection L client: • Apply for a socket connection server (indicating IP address and port number) L The server ends up with a connection request and generates a new socket ( Port greater than 1024 less than 65535) and the client to establish a connection and communication, the original monitor socket continues to listen. The connection is done through the constructor. Lpublic Socket (addressfamily addressfamily, SocketType sockettype, ProtocolType protocoltype) ·addressfamily member designation The addressing scheme that the Socket uses to resolve addresses. For example, internetwork indicates that when the Socket is connected using an IP version 4 address. SocketType defines the type of Socket to open the socket class uses the ProtocolType enumeration to notify the Windows Sockets API of the requested protocol l at least to define the IP and port number of the remote host to connect to. L port number must be between 1 and 65535, preferably after 1024. The remote host to be connected must be listening on the specified port, which means you cannot connect to the remote host at will. • such as: ipaddress addr = Ipaddress.parse ("127.0.0.1"); ipendpoint ENDP = new IPEndPoint (addr, 10001);

Server binding First: Serverwelcomesocket.bind (ENDP)

Client reconnection: Clientsocket.connect (ENDP)

L One socket can only connect one host at a time. Lsocket cannot be used again after it has been closed. L Each Socket object can be connected to only one remote host. If you want to connect to more than one remote host, you must create multiple socket objects. L------------------Related Classes--------------------------Lipaddress class: Contains an IP address Lipendpoint class that contains a pair of IP addresses and port numbers L--------------------Methods-- ----------------------------Lsocket (): Create a Socketlbind (): Bind a local IP and port number (IPEndPoint) Llisten (): Let the socket listen for incoming connection attempts, and specify the listening queue capacity lconnect (): Initializes a connection to another socket Laccept (): Receives the connection and returns a new Socketlsend (): Output data to Socketlreceive (): Read data from Socket Lclose (): Close socket (destroy connection)

Socket related Concepts

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.