Phpsocket programming instance

Source: Internet
Author: User
Because the client program interacts with the third-party payment interface on the webpage, I think this can be implemented simply. Put a socket server on the third-party payment callback page, and the client program interacts with the socket server, in this way, the final business logic is processed. For socket programming in php, the simple instance code is as follows: SERVER :? Phpset_time_limit

Because the client program interacts with the third-party payment interface on the webpage, I think this can be implemented simply. Put a socket server on the third-party payment callback page, and the client program interacts with the socket server, in this way, the final business logic is processed. For socket programming in php, the simple instance code is as follows: SERVER :? Php set_time_limit

Because the client program interacts with the third-party payment interface on the webpage, I think this can be implemented simply. Put a socket server on the third-party payment callback page, and the client program interacts with the socket server, in this way, the final business logic is processed.

The simple example code for socket programming in php is as follows:

Server:


   

Client:


   

Interaction with c ++, client:

#include 
  
    #include 
   
     #pragma comment(lib,"ws2_32.lib") using namespace std;  int main(int argc, char* argv[]) {     WSADATA wsaData;     WORD wVersionRequested=MAKEWORD(2,2);     int err = WSAStartup(wVersionRequested,&wsaData);     if (!err)     {         cout<<"inital socket success"<
    
     >sendBuf;                 if (sendBuf==NULL)                 {                     break;                 }                  send(sock,sendBuf,strlen(sendBuf),0);                 Sleep(500);                 recv(sock,recvBuf,1024,0);                 cout<
     
    
   
  

Interaction with c/c ++ programs. The php server should read data in binary mode:

In addition, when sending data, \ 0 must be added at the end of the string:

Do {// $ buf = socket_read ($ connection, 1024, PHP_NORMAL_READ); $ buf = socket_read ($ connection, 1024, PHP_BINARY_READ ); // exit the connection condition var_dump ($ buf); if ($ buf = "quit") {socket_write ($ connection, "bye \ 0"); break ;} else if ($ buf = "isok") {socket_write ($ connection, "OK \ 0");} echo $ buf; socket_write ($ connection, "copy that \ 0");} while (1 );

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.