Home > Backend Development > PHP Tutorial > PHP 与 C 通信 .

PHP 与 C 通信 .

WBOY
Release: 2016-06-13 13:17:05
Original
1049 people have browsed it

PHP 与 C 通信 求助..........
功能:修改用户账户
服务器端是 C语言 UDP协议
ip:8.14.26.53
port:34556


客户端是 PHP

如何发包过去?

服务器提供的协议:

1、包头
Typedef struct
{
unsigned short ushLength; //包长度
unsigned int uSequence; //请求包seq  
unsigned short ushCmd; //命令(0x2用户修改密)
char cResult;  
}PkgHead;
 
2、修改密码
Typedef struct
{
Char cStx; //0x2
PkgHead stHead;  
Unsigned int Uin; //用户ID
Unsigned short ushUserNameLength;//用户名长度
Char sUserName[]; //用户名buf
Unsigned short ushPasswdLength; //密码长度
Char sPasswd[]; //密码buf
Char cEtx; //0x3
}ReqPasswdResetPkg;
 
Typedef struct
{
Char cStx;
PkgHead stHead;
Char eStx;
} RespPasswdResetPkg;


------解决方案--------------------
应该是socket,去查查资料吧
------解决方案--------------------
pack将每一个数值打包到大端, 拼为字节流写出去就行了。

C服务端注意#progma pack(1)保证结构体无填充, 否则PHP这端处理起来还是麻烦了点.

建议协议尽量走JSON/XML, 对于C还是PHP还是其他任何语言都是有利的, 现在不流行二进制协议了.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template