473,725 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HELP: send binary replies back and forth ???

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 = getBinaryRecord s();
foreach($record s as $rec) {
sendBinary($rec );
while (awaitReply() != ACK) {
sendBinary($rec );
}
}
sendBinary(ACK) ; // done
}
Aug 17 '05 #1
2 2528
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 = getBinaryRecord s();
foreach($record s 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
Aug 17 '05 #2
You're right. my MD satellite device can not support those advanced features
(actually is a GPRS device), but security on that side is not an issue. It's
a client, not a server. And I will use MD5 (and I don't mean Mystery Device
5 here :)) for minimal but fairly robust way to verify data integrity with a
secret password as part of the soup that MD5 is applied on.

Anyway, forget about all that... It does look like I won't be able to use
apache (even though the timeout won't be an issue.. and yes, you can use a
simple php function to set the timeout), .. but there's no reason not to use
php instead of perl/java.

I know you can write whole webservers in php (see nanoweb
http://nanoweb.si.kz/) but I need something more simple.

Issues in writing php server are:
- chroot / run under certain user privileges that would disallow someone to
execute shell commands.
- ensure certain number of concurrent connections but not make it vulnerable
to DOS attacks.
- server start/stop scripts

Lisa

"Erwin Moller"
<si************ *************** *************** @spamyourself.c om> wrote in
message news:43******** *************** @news.xs4all.nl ...
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 = getBinaryRecord s();
foreach($record s 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

Aug 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
9135
by: Patrick | last post by:
Hello all! I am porting an application from C++ to Java and have run into a problem using the DataInputStream reader object. The file I am trying to read in is anywhere from 20 to 60 MB and has a short (25 lines or so) ASCII text "header". The file structure is a double dimensioned array of objects. The ASCII header defines how many "columns" (the first array index) there will be in the file. After the ASCII header, the first value is...
5
7499
by: Charles F McDevitt | last post by:
I'm converting some old programs that use old iostreams. In one program, the program is using cout to output to the stdout stream. Part way through, the program wants to put some binary data out, and changes the iostream to binary like this: cout << "this is text" << eol; binary(cout); cout << "this is binary" << eol; text(cout); cout << "back to text mode" << eol;
12
5911
by: Adam J. Schaff | last post by:
I am writing a quick program to edit a binary file that contains file paths (amongst other things). If I look at the files in notepad, they look like: <gibberish>file//g:\pathtofile1<gibberish>file//g:\pathtofile2<gibberish> etc. I want to remove the "g:\" from the file paths. I wrote a console app that successfully reads the file and writes a duplicate of it, but fails for some reason to do the "replacing" of the "g:\". The code...
16
2536
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client uses IE to talk with a server. The user on the client (IE) sees an ASP net page containing a TextBox. He can write some text in this text box and push a submit button.
4
3739
by: David Hirschfield | last post by:
I have a pair of programs which trade python data back and forth by pickling up lists of objects on one side (using pickle.HIGHEST_PROTOCOL), and sending that data over a TCP socket connection to the receiver, who unpickles the data and uses it. So far this has been working fine, but I now need a way of separating multiple chunks of pickled binary data in the stream being sent back and forth. Questions:
0
1163
by: David Hirschfield | last post by:
I'm implementing a relatively simple inter-application communication system that uses asyncore/asynchat to send messages back and forth. The messages are prefixed by a length value and terminator string, to signal that a message is incoming, and an integer value specifying the size of the message, followed by the message data. My question is: how can I produce a short terminator string that won't show up (or has an extremely small...
29
5084
by: Harlin Seritt | last post by:
Hi... I would like to take a string like 'supercalifragilisticexpialidocius' and write it to a file in binary forms -- this way a user cannot read the string in case they were try to open in something like ascii text editor. I'd also like to be able to read the binary formed data back into string format so that it shows the original value. Is there any way to do this in Python? Thanks!
4
2483
by: Joseph Geretz | last post by:
We use a Soap Header to pass a token class (m_Token) back and forth with authenticated session information. Given the following implementation for our Logout method, I vastly prefer to simply code m_Token = null in order to destroy the session token when the user logs out. However, I'm finding that setting class instance to null results in no header being sent back to the client, with the result that the client actually remains with an...
15
2998
by: JoeC | last post by:
I am writing a program that I am trying to learn and save binary files. This is the page I found as a source: http://www.angelfire.com/country/aldev0/cpphowto/cpp_BinaryFileIO.html I have successfully created and used txt files. I am trying to save then load in an array of pointers to objects:
0
8888
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9176
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9113
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8097
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.