PHP Passing C Struct Data Throught Socket Programming

is it possible to make a c-like binary data(structure) in PHP

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.

receiving reversed data in c socket programming

In your Server program you need to convert response header integers to from host byte stream to network order. You should use htons() or htonl() on it first. If you're receiving an integer in clinet, you should use ntohs() or ntohl().



Related Topics



Leave a reply



Submit