開發板phpinfo部分信息:
[html]
- System
- Linux ShiGuang 2.6.32.2-FriendlyARM #2 Fri Aug 19 10:45:24 CST 2011 armv4tl
- Configure Command
- './configure' '--prefix=/usr/local/php_arm' '--host=arm-linux' '--target=arm-linux' '--enable-sockets'
- DOCUMENT_ROOT
- /usr/local/apache_arm/htdocs
- HTTP_HOST
- 192.168.1.120
post_datas.php
[php]
- <span style="font-size:18px;"><?php
- @header("content-type:text/html; charset=utf-8");
- error_reporting(E_ALL);
- set_time_limit(0);
-
- $user = $_REQUEST['user'];
- $passed = $_REQUEST['passwd'];
- $para = $_REQUEST['para'];
-
- $service_port = 9090;
- $address = "192.168.1.97";
-
- $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
- if ($socket < 0)
- {
- echo "socket_create() failed: reason: " . socket_strerror($socket) . "\n";
- }
-
- $result = socket_connect($socket, $address, $service_port);
- if ($result < 0)
- {
- echo "socket_connect() failed: reason: " . socket_strerror($result) . "\n";
- }
-
- $in = $user . $passed . $para;
-
- $result = socket_write($socket, $in, strlen($in)) ;
- if(!$result)
- {
- echo "socket_write() failed: reason: " . socket_strerror($socket) . "\n";
- }
-
- while($out = socket_read($socket,256))
- {
- echo $out;
- break;
- }
-
- socket_close($socket);
- ?>
- </span>
Mini2440Activity.java
[java]
- package sg131971.mini2440;
-
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
-
- import org.apache.http.HttpResponse;
- import org.apache.http.NameValuePair;
- import org.apache.http.client.ClientProtocolException;
- import org.apache.http.client.HttpClient;
- import org.apache.http.client.entity.UrlEncodedFormEntity;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.impl.client.DefaultHttpClient;
- import org.apache.http.message.BasicNameValuePair;
- import org.apache.http.util.EntityUtils;
-
- import Android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
-
- public class Mini2440Activity extends Activity {
-
- public class myButtonListener implements OnClickListener {
-
- private HttpResponse response;
- private String tmpString;
-
- public void onClick(View arg0) {
- // TODO Auto-generated method stub
- HttpClient httpclient = new DefaultHttpClient();
- HttpPost httppost = new HttpPost("http://192.168.1.123/post_datas.php");
-
- try {
- List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
- nameValuePairs.add(new BasicNameValuePair("user", "root"));
- nameValuePairs.add(new BasicNameValuePair("passwd","shiguang"));
- nameValuePairs.add(new BasicNameValuePair("para","58402F01"));
- httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
-
- response = httpclient.execute(httppost);
- tmpString = EntityUtils.toString(response.getEntity());
- System.out.print(tmpString);
- } catch (ClientProtocolException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
-
- private Button myButton;
-
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
-
- myButton = (Button) findViewById(R.id.myButton);
- myButton.setOnClickListener(new myButtonListener());
- }
- }
Android程序與上一篇文章的程序完全一樣 http://www.linuxidc.com/Linux/2012-02/54795.htm
結果截圖: