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.
addresses can be written here and only ip addresses can be written here. If I write localhost, it will be wrong.
3. Obtain the connection result. If the connection is successful, we can continue to do what we want to do. If the connection fails, we will do what we will do later.
4. Disable socket socket_close ()
PHP socket request example:
Error_reporting (E_ALL );Echo "/* Obtain the website server port */
Socket_shutdown ()
This function allows you to close a read, write, or specified socket
Socket_strerror ()
Returns a detailed error for the specified error number
Socket_write ()
Write data to the socket cache
Socket_writev ()
Write data to a scatter/aggregate array
Note:The Socket_read function will always read the shell data until the
socket is not connected and (when a sendto call sends a datagram socket, the request for sending or receiving data is not accepted.
I created two files xx. php that are executed on the server. X. php is a file executed on the client.
Xx. php
// Set some basic variablesGlobal $ lat, $ lnt;$ Host = "192.168.1.110 ";$ Port = 8080;// Set the timeout valueSet_time_limit (0 );// Create a
("Connect Error! ");Exit (1);}if ((Recvbytes=recv (SOCKFD, buf, maxdatasize, 0)) ==-1) {Perror ("Recv Error! ");Exit (1);}Buf[recvbytes] = "n";printf ("Received:%s", buf);Close (SOCKFD);}The client program first obtains the server IP address through the server domain name, then creates a socket, calls the Connect function to establish the connection with the server, receives the data sent from the server a
, always receive message/private void CreateMessage () {try {System.out.println ("Wait for user access:");
Use Accept () to block waiting for a client to request a socket socket = server.accept ();
SYSTEM.OUT.PRINTLN ("User access:" + socket.getport ()); Open a child thread to wait for another socket to join new thread (new Runnable () {public void run () {Create
program will always block at the receive () method, which is certainly not possible for the client, in order to avoid this problem, We use the Datagramsocket class's Setsotimeout () method on the client to develop the maximum blocking time for the receive () method and specify the number of times the datagram will be re-sent, and if each block times out and the number of postbacks reaches the set limit, the client is shut down.6. The UDP server uses the same
. You should test them first, if the connection is still unavailable, send the exception information.In addition, the Socket connection is prone to problems:1) The server cannot be started due to a port conflict;2) the IP address is incorrect. The IP address is divided into the local address, lan address, and Wan address. Test the IP address in different environments. If the IP address is incorrect, it cannot be accessed by the client, in addition, pr
= Socket_accept ($socket);if ($connection){Socket_write ($connection, "you have connected to the socket.../n/r");}?> You should use your command prompt to run this example. The reason is that this will produce a server instead of a Web page. If you try to run the script using a Web browser, chances are that it will exceed the 30-second limit. You can use the fol
If a problem occurs, log
If an error occurs when you call the connect socket accept function, perror ("socket"); perror ("Connect"); printf ("% s \ n", strerror (errno )); can make specific errors
The select function emphasizes again:
Socket operation on Non-socket errors m
recipient's address * wait_seconds: Waiting For timeout seconds. If it is 0, it indicates normal mode * succeeded (not timed out) 0 is returned,-1 is returned for failure,-1 is returned for timeout, and errno = ETIMEDOUT */int connect_timeout (int fd, struct sockaddr_in * addr, unsigned int wait_seconds) {int ret; socklen_t addrlen = sizeof (struct sockaddr_in); if (wait_seconds> 0) activate_nonblock (fd); ret = connect (fd, (struct sockaddr *) addr, addrlen ); if (ret
Test read_timeout
int
the tag value as writemultibyte () As a character set. For example, the following code sends a Unicode-encoded string:
Socket. writemultibyte ("example", "Unicode ");
The method for passing a value to a socket object relies entirely on the types of all your data and the types of data accepted by the Service. Using a socket object, you can useWrite a telnet and p
The related code is as follows: $ socketsocket_create (AF_INET, SOCK_STREAM, $ commonProtocol) ordie ( quot; cannotcreatesocketn quot;); bind the socket to the port $ resultsocket_bind ($ socket, $ host, $ port) ordie ( quot; cannotbindporttosocketn quot;); start to listen to this port $ resultsocket_listen ($ so socketphp
The related code is as follows: $ socket
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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service