PHP:Socket binary message to c-server

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • scallst@gmail.com

    PHP:Socket binary message to c-server

    Hi!
    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
    string.



    Thank you in advance.
    Scall

  • Chung Leong

    #2
    Re: PHP:Socket binary message to c-server

    See http://fi.php.net/pack/

    Comment

    • scallst@gmail.com

      #3
      Re: PHP:Socket binary message to c-server

      Hi! Chung,

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

      Thank you,
      Scall

      Comment

      Working...