Lordkirin Posted March 26, 2008 Share Posted March 26, 2008 ??? My company is making a ethernet device that we want to send a data steam to a mysql database. I was told by a friend that I should send the data to a server using a post server or a socket server. Our device would need to be able to send a binary stream of data and have a comformation data sent back to it. All we are sending is about 256 bytes of data at one time and want to receive back the datetime stamp and a Receive byte message. Which way would be the best way to do this and have it secure? If someone has a suggestion and maybe a link to some code it would be great. Thanks Quote Link to comment Share on other sites More sharing options...
s0c0 Posted March 26, 2008 Share Posted March 26, 2008 Two ways. The more difficult of your options is to use a SOAP. The easier one is to use cURL over HTTPS. A script on the receiving server would that handle the posted data, insert into a table, the insert function returns a dateTime stamp which is then posted back to the other server. Pretty simple. For security if the server you are sending data too will always have the same ip address due a check on the receiving server for that IP, additional security can be done by passing a funky string looking hashed string (a token of sorts) over as POST variable and only accepting the posted data if the token matches. That makes it pretty secure. Quote Link to comment Share on other sites More sharing options...
Lordkirin Posted March 26, 2008 Author Share Posted March 26, 2008 Thank you. I have not herad of cURL. I will have to look into that. I was wonder about soap too. Right now we don't have the https code for our processor. We are doing the proto type first to prove the consept. could you still use cURL? Quote Link to comment Share on other sites More sharing options...
s0c0 Posted March 28, 2008 Share Posted March 28, 2008 Yeah you can just send data over regular HTTP. Unfortunately the vpn won't work so i can't snag an example of using cURL, but see how far you will get with whats available on php.net. It took me a while to get it down. But basically it works just like a regular php form post, but instead you are doing the form submission programatically. For instance if you're application was sending stock quotes you would post the data to http://yourserver.com/receive.php or whatever. That receiving script would look something like this: if($_SERVER['REMOTE_ADDR']=='10.10.10.10' && $_POST['token']='adhggcgh6786acacaadf') { $sql="INSERT INTO yourtable SET quote='60 a share'"; mysql_query($sql); $key = mysql_insert_id(); $sql="SELECT date_time FROM yourtable WHERE primary_key='$key'"; $result = mysql_query($sql); $array = mysql_fetch_assoc($result); // here is where you would post back to the other server with cURL sending it $array['date_time'] or whatever you want } The $_SERVER['REMOTE_ADDR'] will verify its coming from a permitted server (though this information can be spoofed) and the $_POST['token'] will contain the password for added security. There are ways to make this even more secure such as sending HTTPS through an IPSEC tunnel etc... but if this isn't a huge project you are probably okay with that, but i warned you. You could also send everything via SSH using PHP, all different things I would look at depending on how paranoid I was....or how much coffee I had before the meeting. Or using the token method you could even half a set of alternating tokens. Ok I am done. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.