如何创建Android上的HTTP服务器桌面可以访问(反之亦然)使用NanoHTTPD反之亦然、桌面、服务器、Android

2023-09-04 10:40:17 作者:四裤全输

使用可用的WiFi IP(即192.xxx.xx,使用后8080),我想创建一个Android的http服务器,可以连接,并且可以通过桌面访问,这样我可以将文件传送到Android设备。

Using an available WiFi IP (i.e. 192.xxx.x.x, using post 8080), I'd like to create a http server in android that can connect and can be accessed by a desktop so that I can transfer files to the android device.

更新: 目前,我正在尝试NanoHTTPD,但我似乎无法让对Android设备的样品的HelloWorld运行。

Update: I'm currently trying out NanoHTTPD but I can't seem to make the sample HelloWorld run on android device..

我改变了世界您好code,并使其扩大活动来代替,而创建的对象的 nanohttpd 。

I changed the hello world code and made it extend activity instead and created an object nanohttpd.

我更改为指定要使用什么端口,但在进一步的调试,我发现服务器套接字没有getInetAddress可言。我以为NanoHTTPD不再需要进一步的配置......?

I modified up to specifying what port to be used but upon further debugging, I found out that the server socket has no getInetAddress at all. I thought NanoHTTPD no longer needs further config...?

推荐答案

嘿,事实证明,NanoHTTPD是卓有成效的,但我做了一些调整...

Heh, as it turns out, NanoHTTPD does the trick but I made some adjustments...

检查设备连接。

Check if the device is connected.

我使用的样本来自管理无线和的 wifi网络管理创建检测所有可用的WiFi了WiFi经理,返回ScanResults列表,连接扫描结果进账的IP地址。

I used samples from manage wifi and wifi network management to create a WiFi Manager that detects all available WiFi, returns list of ScanResults, connected Scan Result and fetched the IP address.

做了NanoHttpd作为一类具有单一实例。

Made the NanoHttpd as a class with singleton instance.

从无线管理器所产生的连接ScanResult,我的得到IP地址,并通过它,并给nanohttpd实例的端口号。

From the resulting connected ScanResult of WiFi Manager, I got the IP Address and passed it and a port number to the nanohttpd instance.

NanoHttpd nanoInstance =新Nanohttpd(); 字串[] args = NULL; ARGS [0] = IP地址; ARGS 1 = 8080; //或8081 ..等 nanoInstance.main(参数);

NanoHttpd nanoInstance = new Nanohttpd(); String[] args = null; args[0] = the ip address; args1 = 8080; // or 8081.. etc nanoInstance.main(args);

之后,我终于到达了响应页面。 =]

After that I finally reached the response page. =]