Jump to content

Sending data across the net


Lordkirin

Recommended Posts

??? 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 :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.