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还是其他任何语言都是有利的, 现在不流行二进制协议了.