This is C code.
#pragma pack(push,1)
typedef struct _DATA_PKT_D1
{
char length[2];
char command[2];
char src[64];
char lordId;
char user_id[20];
int level;
char isFine;
char company_code;
}DATA_PKT_D1;
#pragma pack(pop)
DATA_PKT_D1 *pkt = malloc(sizeof(DATA_PKT_D1);
//send pkt through TCP socket.
Data packet is 95byte.
I know php has also tcp socket function.
But, is it possible to make the packet exactly same in php? (95 byte I mean)
and send the data through tcp?
I doubt that php has binary level struct functionality…
Any hints plz~
Yeah, it’s totall possible to construct binary data with PHP, although a bit, no, a lot, less elegant than with C. You need the pack/unpack functions, that let you write binary buffers from php variables. see http://php.net/manual/en/function.pack.php
I’ve implemented UDP servers and clients for binary protocols (even encrypted) in the past, it’s ugly but it works. the only thing you should be careful with is endianness.