Alibabacloud.com offers a wide variety of articles about socket operation on non socket, easily find your socket operation on non socket information here online.
describes the three-time handshake creation process of TCP in the socket and the socket function involved. Now that we introduce the four-time handshake in the socket to release the connection, see:Figure 2, TCP four-time handshake sent in socketThe process is as follows:
An application process first calls close to actively close the connection, when TC
the first example. You need to listen to a specified socket and process user connections.$ Commonprotocol = getprotobyname ("TCP ");$ Socket = socket_create (af_inet, sock_stream, $ commonprotocol );Socket_bind ($ socket, 'localhost', 1337 );Socket_listen ($ socket );// Accept any incoming connections to the server$ C
returns at the second time of the three handshake, while the server-side accept returns for the third time on the three handshake. 5, the socket in TCP Four handshake release connection detailed
This paper introduces the process of three handshake of TCP in socket and the socket function involved. Now we introduce the process of the four handshake release connec
Socket...\n\r");
}
?
You should use your command prompt to run this example. The reason is because there will be a server, not a Web page. If you try to run the script using a Web browser, it is likely that it will exceed the 30-second limit. You can use the following code to set an unlimited run time, but it is recommended that you run it using the command prompt.
set_time_limi
. Now that we introduce the four-time handshake in the socket to release the connection, see:Figure 2, TCP four-time handshake sent in socketThe process is as follows:
An application process first calls close to actively close the connection, when TCP sends a FIN M;
After the other end receives fin m, perform a passive shutdown to confirm the fin. Its reception is also passed as a file terminator to the application process, because the re
passive shutdown to confirm the FIN. Its receipt is also passed to the application process as a file Terminator, because the receiving of FIN means that the application process can no longer receive additional data on the corresponding connection;After a period of time, the application process receiving the file Terminator calls close to close its socket. As a result, TCP also sends a fin n;The source send
: BOOL PASCAL far closesocket (SOCKET s); parameter s the socket descriptor to be closed. If no error occurs, closesocket () returns 0. Otherwise the return value is Socket_error. These are some of the common API functions of the socket API, the following is a piece of code: Client code: #include #include #pragma comment (lib, "Ws2_32.lib") int main () { int
-ano to check the port status. my port number is Port 1935.
Check that the port is already in the LISTENING status. Next, we only need to run the client program to connect. Code on
";}While ($ out = socket_read ($ socket, 8192) {echo" received the server's return message! \ N "; echo" accept the following content: ", $ out;} echo" close SOCKET... \
connection is established.
Summary: The client's connect returns in the second time of the three handshake, while the server-side accept is returned for the third time in the three-time handshake.
5, the socket TCP Four handshake release connection detailedThe above describes the three-time handshake creation process of TCP in the socket and the socket
to the connected socketSOCKET_SENDMSG () Send message to socketSocket_sendto () sends a message to the socket at the specified addressSocket_set_block () set as block mode in socketSocket_set_nonblock () set to non-block mode in socketSocket_set_option () Set socket optionsSocket_shutdown () This function allows you to close a read, write, or specified socketSocket_strerror () returns a detailed error for
error occurs, closesocket () returns 0. Otherwise the return value is Socket_error.These are some of the common API functions of the socket API, the following is a piece of code:Client code:#include #include #pragma comment (lib, "Ws2_32.lib")int main (){int err;WORD versionrequired;Wsadata Wsadata;Versionrequired=makeword (a);Err=wsastartup (versionrequired,wsadata);//version information of the Protocol libraryif (!err){printf ("Client nested word h
no error occurs, closesocket () returns 0. Otherwise the return value is Socket_error. The above is the socket API some common API functions, the following is a section of code://Client code: #include
#include
#pragma comment (lib, "Ws2_32.lib") int main () {int err; WORD versionrequired; Wsadata Wsadata; Versionrequired=makeword (a); Err=wsastartup (versionrequired,wsadata);//The version information of the Protocol Library if (!err) {pr
are some common API functions of the socket API. The following is a piece of code:// Client code:# Include # Include # Pragma comment (Lib, "ws2_32.lib ")Int main (){Int err;Word versionrequired;Wsadata;Versionrequired = makeword (1, 1 );Err = wsastartup (versionrequired, wsadata); // version information of the Protocol LibraryIf (! Err){Printf ("the client nested word has been opened! \ N ");}Else{Printf
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.