First of all as time goes on, I will keep adding to it inside, know I think it should end.
This document is a summary of my learning, so if someone has a part to letter pointed out that one of the error or not, that I'm grateful to tears in the rain. I assume that the reader already for socket connection establishment process and various state transitions are more familiar with, for the purpose of this document is to clarify concepts instead introduces concepts. When you use socket programming, we all know that network traffic before it is first necessary to establish the connection, the connection establishment is done by some of the socket operation. Then, make the connection process can roughly be divided into the following steps: 1. establishing socket Sockets. 2. to the socket address, the address given is not the usual concept of a network address. 3. establish a socket connection. 1. establishing socket socket with socket socket, we actually created a data structure. This data structure is the most important information is specified by connection type and use of the protocols, there are also some connection queue operations structure field (this does not involve them first). When we use the socket function later, if successful, returns an int type descriptors, it points to a front that is maintained in the kernel data structure in the socket. Our action is through this descriptor and the role to the data structure. This is just like us in the creation of a file from a file descriptor of the file operations are carried out by file descriptor instead of directly to the inode data structure. I used a file descriptor, for example, because the socket data structures are and inode data structure are closely related, it is not a separate exists in the kernel, which is located in a VFSinode structure. Therefore, there are some of the more abstract properties, we can use file operations to inappropriate for analogy to deeper understanding. As mentioned earlier, when the socket has been established, we can get a file descriptor that socket descriptor. As we operate on file, we can write data inside the socket will specify data to the US, this place can be a remote host, or it can be a local host. If you are interested, you can also use socket mechanism to achieve the efficiency of the IPC, but is relatively low, try it on the line (I have not tried). 2. to the socket address given in accordance with the purpose of establishing socket, gives the socket address in two ways: server-side use bind, the client uses connetc. Bind: we all know that as long as you use IP, prot can distinguish between a tcp/ip connection (of course this connection is a connection channel, if you want to distinguish between the specific connection between the host, you need a third property hostname). We can use the bind function to use for a server-side routines in the socket address of the given communication and port. Here we call communication of IP addresses and ports together to form a socket address, and specify a socket to use specific IP and port combinations for the passage of the process is given an address of the socket. To give the socket address, you have to use a data structure to indicate the specific socket address, this data structure is structsockaddr. On its use and I do not say, because this document aims to clarify the concept rather than a description of how to use it. The role of the Bind function is this particular socket marked address information for the data structure and socket socket, that is, given an address of the socket. But in the concrete implementations, how did the two of them together, I do not know. A specific socket address lifetime is bind successful after the connection is disconnected. You can build a socket data structure and socket address of the data structure, but not before they bind the two are not related to bind two later they have a relationship. This relationship has been maintained to the connected end, when a connection ends, the socket data structure and socket address data structures also exist, but they have no relationship between the two. If you wish to use this socket on the socket address when connecting, you bind the two of them. Then specify a time, I said in this connection is a connection channel, instead of a specific host. Bind specified IP are usually local IP (generally not specifically designated, but use INADDR_ANY declared), but the most important role is to specify the port. On the server side of the socket to bind future is listen to the socket address ready to connect. Connect: for clients that do not use bind (and not cannot be used, but no significance), they will build by connet function socket and socket address. The socket address of which is that it wants to connect to the server-side socket address. In the connect to establish socket and socket address relationship at the same time, it is also trying to establish a remote connection. 3. establish a socket connection is ready to establish a connection to the server-side in two steps: bind, listen; client a step: connct. If you accept a connect on the server side, and the client got the confirmation that accept, then a connection is established.
No comments:
Post a Comment