dtx3006 2012-09-21 11:56
浏览 77
已采纳

Titanium通过系绳访问文件

I have an app that needs to access a local WAMP server in order to be served by a PHP script, but only when the USB cable is plugged in. The app needs to operate completely offline. I have researched using USB tunneling and such but so far there is no clean and simple solution. Perhaps I am looking too far and wide for a solution?

The end result for this project is that I need to copy a database from the WAMP server to the devices database. I plan on feeding it a JSON-parseable string via the PHP script.

I am trying to achieve this with XHR:

var url = "http://10.0.2.2:8080/home/yey.php";
    var xhr = Ti.Network.createHTTPClient({
        onload: function(e){
            alert(this.responseText);
        },
        onerror: function(e){
            alert(e.error);
        },
        timeout: 5000
    });

xhr.open("GET", url);
xhr.send();

Other IP addresses I have tried are:

192.168.0.1
127.0.0.1
10.0.2.2
// My PC's IP

// and ports
8888
80
8080

I am currently using easyPHP for development but the final product will run on a dedicated server box.

Is there any other way for Titanium to access a php script hosted locally?

  • 写回答

1条回答 默认 最新

  • dongyu1983 2012-09-21 12:59
    关注

    You can access files with the specified IP addresses only when you use the emulator. Not on the device.

    If you want to use the device, you will need to specify the actual IP address of your computer. I guess you know how to find your IP address locally right?

    If your router is 192.168.0.1, then usually your machine will have something else instead of the 1

    • 10.0.2.2 is the parent machine (thus, in emulator, the computer running the emulator)
    • 192.168.0.1 is most likely your router
    • 127.0.0.1 is the device itself

    This will work locally, but not specifically for usb. Why do you need that anyways?

    The port to use depends totally on the setup of your apache on your computer.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)