PHP uses Berkeley's socket library to create its connection. You can know that socket is just a data structure. You use this socket data structure to start a session between the client and the server. This server is always listening and preparing to generate a new session. When a client connects to the server, it opens a port on which the server is listening for a session. At this time, the server accepts the client's connection request, and then performs aloop. Now the client can send information to the server, and the server can send information to the client.
To generate a Socket, you need threevariables: a protocol, a socket type and a public protocol type. There are three protocols to choose from when generating a socket. Continue reading below to get detailed protocol content.
Defining a public protocol type is an essential element for connection
Let us start with a simple example --- a string that receivesinput characters, processes and Return thisstringto the client's TCP service.The code is as follows:
The above is the detailed content of Detailed introduction to php Socket programming. For more information, please follow other related articles on the PHP Chinese website!