简体   繁体   English

Android - Web服务器通信

[英]Android - Web Server Communication

I would like to create a dummy application for connecting my Android phone to my latop and printing out messages through the browser. 我想创建一个虚拟应用程序,用于将我的Android手机连接到我的镭拓,并通过浏览器打印出消息。 (Imagine twitter without any of the functionality) (想象一下没有任何功能的推特)

From my thinking I will be using the following: 根据我的想法,我将使用以下内容:

Client - Android Phone, application Server - Latop, tomcat, servlet, browser 客户端 - Android手机,应用服务器 - Latop,tomcat,servlet,浏览器

The idea is the application will use Wi-Fi to establish communication between the phone and the laptop, is it required for the android application to specify the use of the phones 3g or Wi-Fi connection in the code. 这个想法是应用程序将使用Wi-Fi建立手机和笔记本电脑之间的通信,是否需要Android应用程序指定在代码中使用手机3g或Wi-Fi连接。 Would sockets be an appropriate choice for establishing a connection? 套接字是否是建立连接的合适选择? How would I go about defining the server to remain open and active looking for incoming connections from a mobile device with which to output the text communicated via a browser. 我将如何定义服务器以保持打开并主动查找来自移动设备的传入连接,通过该移动设备输出通过浏览器传送的文本。

I am so vauge but I am assuming I would need to create the Android Application first, open a connection to the IP and Port of the laptop using a socket connection. 我是如此vauge但我假设我需要首先创建Android应用程序,使用套接字连接打开与笔记本电脑的IP和端口的连接。 Using buffer reader and printwriter communicate a users inputed text from the Android application to a servlet on the server side. 使用缓冲读取器和printwriter将用户输入的文本从Android应用程序传送到服务器端的servlet。 Within the server a simple out.print to the browser should suffice? 在服务器内,浏览器的简单out.print应该足够了吗?

Any thoughts, guidance would be great! 任何想法,指导都会很棒!

can't you just open an http connection using HttpConnection class? 你不能只用HttpConnection类打开一个http连接吗? just search for httpclient android. 只是搜索httpclient android。 (or open http://developer.android.com/reference/org/apache/http/client/HttpClient.html ) (或打开http://developer.android.com/reference/org/apache/http/client/HttpClient.html

then you can connect to any web server out there ... 然后你可以连接到那里的任何网络服务器......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM