Re: [PHP] Sending messages from php to C++ application via UDP socket

2011-05-19 Thread shiplu
On Thu, May 19, 2011 at 3:14 PM, Richard Quadling wrote:

> On 18 May 2011 18:03, shiplu  wrote:
> > Try to think a string is an array of bytes.
> > Parse that array of bytes at C++ end.
> > There should host to network and network to host data conversion
> function.
> > Use them.
> >
> > --
> > Shiplu Mokadd.im
> >
>
> Just to confirm Sniplu's comment really.
>
> For example (see http://unicode.org/faq/utf_bom.html#bom4)
>
> $s_Utf8Bom = chr(0xEF) . chr(0xBB) . chr(0xBF);
>
> This will build the UTF-8 Byte Order Mark.
>
> You can use http://uk.php.net/manual/en/function.pack.php to build a
> binary string comprised of different values based upon C types
> (int/long, signed/unsigned, chars, hex strings, floats/doubles, nulls,
> etc.)
>
> In essence, if you have a C struct that represents the data you need
> to send, then you should be able to compose a suitable string.
>
> If you already have an app that can talk to the media player, then use
> a tool like wireshark to monitor the communication. That, at least,
> will give you real world example of the data you need to send.
>
> Richard.
>
>
If there is already a protocol defined for such communication, use it. To
get hint about this protocol use wireshark like tools.
If no protocol is defined yet. You need to define one.
For this all you have to make a serializer and an unserializer function for
both php and c++ end that obeys the protocol.
Now this serializer can use xml, yml, json, binary, base64  or any different
format..

-- 
Shiplu Mokadd.im
My talks, http://talk.cmyweb.net
Follow me, http://twitter.com/shiplu
Innovation distinguishes between follower and leader


Re: [PHP] Sending messages from php to C++ application via UDP socket

2011-05-19 Thread Richard Quadling
On 18 May 2011 18:03, shiplu  wrote:
> Try to think a string is an array of bytes.
> Parse that array of bytes at C++ end.
> There should host to network and network to host data conversion function.
> Use them.
>
> --
> Shiplu Mokadd.im
>

Just to confirm Sniplu's comment really.

For example (see http://unicode.org/faq/utf_bom.html#bom4)

$s_Utf8Bom = chr(0xEF) . chr(0xBB) . chr(0xBF);

This will build the UTF-8 Byte Order Mark.

You can use http://uk.php.net/manual/en/function.pack.php to build a
binary string comprised of different values based upon C types
(int/long, signed/unsigned, chars, hex strings, floats/doubles, nulls,
etc.)

In essence, if you have a C struct that represents the data you need
to send, then you should be able to compose a suitable string.

If you already have an app that can talk to the media player, then use
a tool like wireshark to monitor the communication. That, at least,
will give you real world example of the data you need to send.

Richard.






-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Sending messages from php to C++ application via UDP socket

2011-05-18 Thread shiplu
Try to think a string is an array of bytes.
Parse that array of bytes at C++ end.
There should host to network and network to host data conversion function.
Use them.

-- 
Shiplu Mokadd.im


Re: [PHP] Sending messages from php to C++ application via UDP socket

2011-05-18 Thread Stuart Dallas
On Wed, May 18, 2011 at 3:16 PM, Schlager, Christian wrote:

>
>
> Hello,
>
> I am a first-time poster. I hope this is the proper way to ask my question:
>
> I have a C++ media player application that I want to control via a php
> website.
> To that end the application has an UDP socket listening for Player
> messages.
> In C++ player messages have the following members:
>
> class MessageHeader
> {
>UINT16  packetSize; // size of message in bytes
> including header
>UINT16  sequenceNum;// sequence number of message
>UINT16  flags;  // flags
>UINT16  msgType;// msg type
> }
>
> class PlayerCommand : public MessageHeader
> {
>WCHAR command[MAX_PATH];// dynamic string
> }
>
>
> The php website is supposed to create an UDP socket in order to send player
> commands (play, stop, next, etc.)
> However, according to the documentation all php socket functions only take
> messages in string format.
> For example, int socket_sendto ( resource $socket , string $buf , int $len
> , 
>
>
> My question is this:
> If it is possible at all, how can I create a $buf - string that represents
> the PlayerCommand class and is accepted by the C++ listening socket?
>


You really want something like JSON, Thrift (http://thrift.apache.org/), XML
or some other format to package the data in a way that will be easily
manipulated at both ends, rather than trying to duplicate the in-memory
representation that your particular C++ compiler of choice is using. Doing
things that way leads to an extremely fragile system.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/