PHP:Socket binary message to c-server

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm new in PHP and I have a problem on sending a socket message to
c-server. I am able to connect using socket_connect but my problem is I
have to setup TCP message in a special format as my c-server is
expacting it in as in c-Structure byte order with binary data.

For example: at server:
typedef struct
{ unsigned char    msg;
  unsigned char    start;
  unsigned char    nCont;
  unsigned char    nError;
  unsigned char    nFunction;
  unsigned short   nRecLen;
  unsigned char    nData[900];
  unsinged char    msg1;
  unsigned char   end ;
} MyMsg;

where nData coulde be in format like:
struct {
          int myid;
          char Name[100];
          char Name2[100];
          int Type;
          int Working;
          int Alarm;
          int Auto;
          char num[20];

How should I setup my string in PHP that can fit in c-byte order like
unsinged short-2 byte, int-4-byte binary number and then character

Thank you in advance.

Re: PHP:Socket binary message to c-server


Re: PHP:Socket binary message to c-server

Hi! Chung,

Thank you for your quick reply. I think this will help me.

Thank you,

Site Timeline