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.
The Socket API is a standard API for practical application development in Web applications. Although the API is simple. However, novice developers may experience some common problems. This article identifies some of the most common pitfalls and shows you how to avoid them.Hidden trouble 1. Ignore return statusThe first pitfall is obvious, but it's a mistake for the easiest developer to make.Suppose you ignore the return state of a function, and when t
variables $ host = "192.168.1.99"; $ port = 1234; // set the timeout value set_time_limit (0 ); // create a Socket $ socket = socket_create (AF_INET, SOCK_STREAM, 0) or die ("cocould not createsocket \ n "); // bind the Socket to the port $ result = socket_bind ($ socket, $
. Next we just run the client program to connect. On the Code
The client is already connected to the service side.
Case two: Code explanation
Set some basic variables $host = "192.168.1.99"; $port = 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
PHP Socket programming process details
Introduction
Socket is used for inter-process communication. Inter-process communication is generally based on the client-server model. In this case, the client-server is an application that can interact with each other. The interaction between the client and the server needs to be connected. Socket programming is responsib
a read, write, or specified socketSocket_strerror () returns a detailed error for the specified error numberSocket_write () write data to the socket cacheSocket_writev () write data to a scatter/aggregate arrayCase ONE: Socket communication DemoServer-side: 1 This is the server-side code for the socket. Then run CMD, note that it is your own program to store 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 receive of fin means that the application process can no
);
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\n");
Start listening for
operation is complete. In asynchronous mode, these calls return immediately.
In addition, in many cases, socket programming is implemented on the client and server based on different situations, and the application program is compiled on the client to send requests to the specified port on the server, at the same time, the preparation of the server application to process the request has been mentioned in the above description; of course, not all
C #. Net synchronous asynchronous socket communication and multithreading Summary
Source: http://www.cnblogs.com/Silverlight_Team/archive/2009/03/13/1411136.html
Synchronous socket communication
Point-to-point online communication supported by socket
The server monitors connections, and the client sends connection requests. After a connection is establishe
; 32-bit IPv4 address, network Byte ordered char sin_zero[8]; UnusedSOCKADDR_IN is a network socket address structure, the size of 16 bytes, defined in the struct SOCKADDR { sa_family_t sa_family; Address family:af_xxx value char sa_data[14]; Protocol-specific Address}SOCKADDR is through the socket address structure, when passed as a parameter
is complete. In asynchronous mode, these calls return immediately.
In addition, in many cases, Socket programming is implemented on the client and server based on different situations, and the application program is compiled on the client to send requests to the specified port on the server, at the same time, the preparation of the server application to process the request has been mentioned in the above description; of course, not all
.
Using the PHP socket extension
Server-side code:
When you write a server, you must first perform an "accept" operation on the server socket using the Stream_socket_accept feature. This function blocks until the client connects to the server, or the timeout expires.//Ensure that the client is connected without timing outSet_time_limit(0);//Set IP and port number$address="127.0.0.1"
(SER_SOCKFD);}
Client Workflow: First call the socket function to create a socket and then call the BIND function to bind it to the native address and a local port number, request a connection to the server, and send the string "Hi,i am client!" to the client via a new socket. Finally, close the socket.
);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\n");Start listening links$res
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, TCP four waveThe four-time handshake in the socket releases the connection process, see:An application process first calls close to actively close the connection, when TCP sends a fin m, and the other end receives Fin m, performs a passive shutdown to confirm the fin. Its reception is also pass
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.