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
} 2 2506
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
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******************************************@spam yourself.com> 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 = 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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,...
|
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:
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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,...
|
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...
| |