Re: HELP: send binary replies back and forth ???
- From: Erwin Moller <since_humans_read_this_I_am_spammed_too_much@xxxxxxxxxxxxxxxx>
- Date: Wed, 17 Aug 2005 14:10:39 +0200
Lisa Pearlson wrote:
> Hi,
>
> My php application (on Apache/Linux) needs to do the following:
>
> The PHP script receives a request from a client (binary), asking for
> certain records of data.
> My PHP script loops through all records and sends each of them ONE BY ONE.
> After each record that my server script sends, it waits for the client to
> confirm proper reception with an ACK (binary digit).
> When there are no more records, my server script sends the client a binary
> digit 0.
>
> So the client initiates a connection to the webserver with my php script,
> and communication then goes back and forth between the server and client a
> couple of times before a 'session' completes.
> Looks like this:
>
> 1. client ---> server (client asks for records)
> 2. client <--- server (server sends record 1)
> 3. client ---> server (client confirms with ACK)
> 4. client <--- server (server sends record 2)
> 5. client ---> server (client confirms with ACK)
> 6. client <--- server (server sends ACK to notify end of records)
>
> Additional info:
> 1. The client is not a webbrowser but a piece of simple hardware that can
> only do simple TCP/IP connections and doesn't come with any specific
> internet application protocol such as HTTP. HTTP is easy enough to
> implement just to exchange binary data, but there's no reason to use HTTP
> other than to be able to communicate with apache.
> 2. The reason I have to send records one by one is because the client is a
> special device with limited read buffer.
> 3. All communication is binary because the connection used is pricy and
> charged by kilobytes of data.
>
> Questions:
>
> 1. A webserver usually doesn't communicate back and forth, rather client
> sends request, server sends reply, and connection is closed. Also, HTTP
> headers generate extra overhead that I really don't need and want
> (generates extra data that we get charged for). How can I accomplish
> communication like the above with apache and php?
>
> I'm afraid I may have to write my own PHP style socket server without the
> use of apache at all. Then it wouldn't have to be HTTP but all binary
> communication only. The problem with this is that I think it might be hard
> to develop something robust in just 2 days. A webserver has a proven track
> record, has security features (think of DOS attacks) and other things that
> would be hard to implement myself. But all my script would need to do is
> the above so it doesn't really need much.
> I don't know how hard it would be to develop a php server that would
> handle concurrent connections and keep running, and is secure enough that
> it woudn't allow DOS attacks or worse, allow execution of commands on the
> linux machine with root privileges. chrooting and other things is
> something I'm not experienced enough with to trust. So I'd like to hide
> behind apache if possible. But communicating binary data without HTTP
> headers has proven impossible from within apache.
>
> Also, how can my script RESPOND in binary data?
> "echo 0" doesn't send the byte value 0, rather the ascii value "0".
> passthru allows binary data to be outputted but only in response to some
> shell command.
> And I guess "echo pack("C", 0)" wouldn't do it either.
>
> If the client could also act as a server, then I could've simply opened up
> a socket in response to the server and communicated back and forth with it
> in a loop, in a single call via apache.
>
>
> Example quasi code that illustrates what I'd like to be able to do.
>
> server.php:
>
> $binary = $GLOBALS['HTTP_RAW_POST_DATA'];
> $size = strlen($binary);
> $arr = unpack( .... , $binary);
>
> if ($arr['request-type'] == 5) {
>
> $records = getBinaryRecords();
> foreach($records as $rec) {
> sendBinary($rec);
> while (awaitReply() != ACK) {
> sendBinary($rec);
> }
> }
> sendBinary(ACK); // done
> }
Hi,
I think your proposed setup will run into trouble.
You make a loop that should wait for a response from your mysterydevice
(Let's call it MD from now :-).
PHP typically responds to 1 request.
PHP also has a default 'scripttimeout' of 30(?) seconds, but that can
probably be modified by you via php.ini.
I think creating a session makes more sense, but that can prove difficult
because your MD probably doesn't support http and cookies *I think*.
Personally I would opt for a solution without PHP.
Perl and Java might be much more suitable for your situation.
About the 'hiding behind apache' for security: Yes, afaik apache is
rocksolid (as long as you don't use obscure modules), but is you MD?
Will your MD have a fixed IP-adres?
If so, you can easily confige Java/Perl/PHP to only communicate with that
IP.
You probably need some authentication too.
I guess you do not want some freak sending data to your MD.
If you can, use SSH2 or something, but I do not know if that will give you a
lot of extra datatraffic.
Just my 2 cents.
Regards,
Erwin Moller
PS: Just curious: Are you building a sattelite? :P
.
- Follow-Ups:
- Re: HELP: send binary replies back and forth ???
- From: Lisa Pearlson
- Re: HELP: send binary replies back and forth ???
- References:
- HELP: send binary replies back and forth ???
- From: Lisa Pearlson
- HELP: send binary replies back and forth ???
- Prev by Date: Re: Date from form to mySQL
- Next by Date: Re: Problem updating PHP Include?
- Previous by thread: HELP: send binary replies back and forth ???
- Next by thread: Re: HELP: send binary replies back and forth ???
- Index(es):
Relevant Pages
|
|