How Socket socket multiple clients simultaneously connected to a port on the server, such as 80? (Translation)

1 Socket socket

       Socket socket continuously funded by ARPA (Advanced Research Projects Agency, ARPA) developed a research group of the University of California, Berkeley. The aim is the TCP / IP protocol software ported to UNIX-like systems. Designers to develop an interface so that applications can simply call the interface communication. This interface continues to improve, culminating in the Socket socket. Linux system uses the Socket, therefore, Socket interface is widely used, and now has become the de facto standard. Functions associated with the socket is contained in the header file in sys / socket.h.

 

2 Socket Socket Profile

       Socket English means "socket", as the process communication mechanism UNIX-like systems, it's as easy as socket help of a computer connected to the Internet communications.

       Before any user communication, first of all you have to apply for a Socket number Socket number corresponds to your own phone number. At the same time to know each other's phone numbers, equivalent to the other side there is a Socket. Then dial call to each other, corresponding to connection request is issued (if not in the same area each other, but also other dial code, corresponding to given network address). If the other party present and idle (the equivalent of another host communications can be turned on and accept the connection request), lift the handset, you can officially call the two sides, the equivalent of a successful connection. During double talk, and the process of receiving a signal is sent from the telephone to the telephone signal corresponds Socket transmission data and receive data from Socket. After the call, the telephone party hangs, corresponding to the Socket closed, withdrawn connection.

       Thus, the communication mechanism with the telephone exchange mechanism Socket very similar. Socket essentially provides the endpoint process communication. Before the process of communication, the two sides must first create a respective end, otherwise there is no way to establish contact and communicate with each other. Socket each half are associated with a description.

  1. {Protocol, local address, local port}. 

       A complete description associated with a Socket is:

 
  1. {Protocol, local address, local port, remote address and remote port}. 

       Each Socket Socket has a unique local number assigned by the operating system. There are three types of sockets: stream socket (SOCK_STREAM), the socket packet (SOCK_DGRAM) and raw socket. Stream socket may provide a reliable, connection-oriented communication flow. If the data is sequentially transmitted by the stream sockets: 1. Then the data arrival order 2 is the remote time. Stream socket may be used by Telnet connection, the WWW service is necessary to transfer the application data sequence, which uses the TCP protocol to ensure reliability of data transmission. Works stream sockets As shown, the two hosts we will look at the network were 18.9 as a server and a client.

       Socket packet defines a connectionless service, data is transferred through packets independently, it is disordered, and does not guarantee reliability. Socket packet user datagram protocol UDP, the data is simply transferred to the other side. It works packet socket 18.10 as shown in FIG.

Figure 18.9 works the stream socket

Works data socket Figure 18.10

 

3 a plurality of clients simultaneously connected to a server

       At this time the server should use multiple threads, each connected on one client give the client open a thread. When listening port should also open a separate thread, or will block the main thread. This has an obvious drawback is that there are N client requests a connection, there will be N threads, a great impact on the performance and the performance of a computer program, you can use the thread pool management.

       The benefits of using the thread pool: frequent mainly used to reduce the overhead of creating and destroying threads bring, so those are often used to perform a short time and need to use the thread pool thread to manage.

recommend:

How many clients connect to a port on the server, such as 80? (Translation)

 

reference:

What is a socket (Socket)

 

 

Guess you like

Origin www.cnblogs.com/zkfopen/p/11206388.html