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.
, so three times shook hands, connection established.
Summary: The client's connect 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 f
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... \ n "; socket_close ($
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... \ n "; socket_close ($
"; $port=1234;//setting the time-out periodSet_time_limit (0);//Create a socket$socket = Socket_create (Af_inet, Sock_stream,0) or Die ("Could not createsocket\n");//bind socket to port$result = Socket_bind ($socket, $host, $port) or Die ("Could not bind tosocket\
PHP Socket Programming Process detailedSockets are used for interprocess communication. Interprocess communication is typically based on a client-server model. At this point, the client-server is an application that can interact with each other. The interaction between the client and the server requires a connection. Socket programming is responsible for establishing an interactive connection between applic
. However, the session between the service program and the customer program may be long (similar to the phone number ), therefore, to speed up the response to the client program connection request, a typical method is to run a background thread on the server host, which processes the communication between the service program and the client program.
To demonstrate the concepts we mentioned above and complete the ssclient program, we will create an ssserver program. The program will create a serve
($ socket, 8192) {48 echo" received server return message successful! \ N "; 49 echo" received content: ", $ out; 50} 51 52 53 echo" disable SOCKET... \ n "; 54 socket_close ($ socket); 55 echo" close OK \ n "; 56?>
Now the c
only data sent from that destination address is received by that socket. The advantage of calling the Connect function is that you do not have to specify the destination address each time you send and receive data.
2> function Prototype:
#include
#include
int connect (int sock_fd,struct sockaddr *serv_addr,socklen_taddrlen);
3> Parameters:
ØSOCK_FD: The socket file descriptor that is returned when the
set_time_limit (0);//Create a socket$socket = Socket_create (af_inet , Sock_stream, 0) or die ("Could not createsocket\n");//bind socket to port $result = Socket_bind ($socket, $host, $port) or Die ("Cou LD not bind tosocket\n ")
release connection detailedThe above 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 a
Socket Programming Principle
1, the introduction of the problem
1 Ordinary I/O operation process :
The I/O command set for UNIX systems is evolved from commands in the Maltics and early systems, in a mode that opens a read/write Off (open-write-read-close). When a user process makes an I/O operation, it first invokes "open" to obtain the right to use the specified file or device and returns an integer called the file descriptor to describe the proce
received .. Socket s = ss. accept (); OutputStream OS = s. getOutputStream (); // The Socket generated by the server side to obtain the output stream OS. write ("Hello, you have received a blessing from the server! \ N ". getBytes (); OS. close (); s. close ();}}The client uses Socket for communication:
The test envir
= 1234;//Set timeout time set_time_limit (0);//Create a socket$socket = Socket_create (af_inet , Sock_stream, 0) or die ("Could not createsocket\n");//bind socket to port $result = Socket_bind ($socket, $host, $port) or Die ("Cou LD not bind tosocket\
;
// Struct hostent * host; assign the Server IP address to the host struct through gethostbyname. If the incoming IP address is a domain name, convert it to an IP address and assign a value.
If (host = gethostbyname ("www.800hr.com") = NULL)
// Or if (host = gethostbyname ("192.168.0.1") = NULL)
{
Herror ("gethostbyname error ");
Return 1;
}
Else
{// Output IP Address: xxx. xxx
Printf ("host: % s \ n", inet_ntoa (* (struct in_addr *) host-> h
-type:text/html;charset=utf-8\r\ncontent-length:{0}\r\n", responsebody.length); - byte[] Responseheaderbytes =UTF8. GetBytes (Responseheader); the + //sending status information to clients A client. Send (statuslinebytes); the //send a response header to the client + client. Send (responseheaderbytes); - //header-to-content separation line $Client. Send (New byte[]{13,10}); $
cacheSocket_recvfrom () accepts data from the specified socket and, if not specified, the default current socketSocket_recvmsg () received a message from IovecSocket_select () multi-channel selectionSocket_send () This function sends data to the connected socketSOCKET_SENDMSG () Send message to socketSocket_sendto () sends a message to the socket at the specified addressSocket_set_block () is set to block
K is confirmed; when the server receives an ACK k+1, the Accept returns, three times the handshake is complete, and the 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 detailed
The three-time handshake establishment process of TCP
process to access the file. Socket descriptors are implemented using file descriptors in UNIX systems.
To create a socket, you can call the socket function.
#include
Parameters:
Purpose: socket () is used to create a socket descriptor, which uniquely identifies a
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.