PHP communicates with C.

Source: Internet
Author: User
PHP and C communication help ...... function: modify the user account server is a C language UDP protocol ip address: 8.14.26.53port: 34556 client is PHP how to send packets in the past? Protocols provided by the server: 1. Baotou Typedefstruct {unsigned1_ushlength; // The package length. PHP communicates with C for help ..........
Function: modifies a user account.
The server is a C language UDP protocol.
Ip: 8.14.26.53
Port: 34556


The client is PHP.

How to send packets?

Protocols provided by the server:

1. Baotou
Typedef struct
{
Unsigned short ushLength; // package length
Unsigned int uSequence; // request packet seq
Unsigned short ushCmd; // command (0x2 user password modification)
Char cResult;
} PkgHead;

2. change the password
Typedef struct
{
Char cStx; // 0x2
PkgHead stHead;
Unsigned int Uin; // user ID
Unsigned short ushUserNameLength; // username length
Char sUserName []; // User name buf
Unsigned short ushPasswdLength; // password length
Char sPasswd []; // password buf
Char cEtx; // 0x3
} ReqPasswdResetPkg;

Typedef struct
{
Char cStx;
PkgHead stHead;
Char eStx;
} RespPasswdResetPkg;


------ Solution --------------------
It should be socket. check the information.
------ Solution --------------------
Pack each value into the big end and write it into a byte stream.

C server note # progma pack (1) ensures that the struct is not filled; otherwise, PHP may be difficult to handle.

We recommend that the protocol use JSON/XML as much as possible, which is advantageous for C, PHP, or any other language. binary protocol is not popular now.

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.