也许与其他人相反,我正在考虑在Android上运行一个Web服务服务器。是否有支持此功能的库?我认为ksoap2例如只用于消费网络服务,而不是为它们服务,对吧?
而且,如果没有冗长的编码,这是不可能的,我只需要在Android上运行一个HTTP服务器,并用它接收二进制文件(通过POST)。
有人能给点提示吗?
Cheers, Marc
也许与其他人相反,我正在考虑在Android上运行一个Web服务服务器。是否有支持此功能的库?我认为ksoap2例如只用于消费网络服务,而不是为它们服务,对吧?
而且,如果没有冗长的编码,这是不可能的,我只需要在Android上运行一个HTTP服务器,并用它接收二进制文件(通过POST)。
有人能给点提示吗?
Cheers, Marc
最后,我打消了在Android端使用Web服务实现它的想法,只是通过Socket Communication和自行设计的协议实现了它,非常像这样:
public class AsyncTaskSocketServer extends AsyncTask<Integer, String, Integer> {
private int id;
private String TAG = "AsyncTaskSocketServer";
private AsyncTaskSocketServer() {
super();
Random generator = new Random();
id = generator.nextInt();
Log.d(TAG, "created with id: " + id);
}
@Override
protected Integer doInBackground(Integer... ports) {
int port = ports[0];
Log.v(TAG, "Trying to start on port: " + port + " with id: " + id);
try {
ServerSocket serverSocket = new ServerSocket(port);
while (!isCancelled()) {
Socket client = serverSocket.accept();
try {
Log.v(TAG, "Listening on port: "
+ port);
BufferedReader in = new BufferedReader(
new InputStreamReader(client.getInputStream()));
String str = in.readLine();
publishProgress(str);
} catch (Exception e) {
e.printStackTrace();
Log.v(TAG, "Exception while socket.accept"+ id);
} finally {
client.close();
}
client.close();
}
} catch (Exception e) {
e.printStackTrace();
Log.v(TAG, "Exception in SocketServer creation" + id);
}
return port;
}
@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
String message = values[0];
try {
NetworkQueue.MESSAGE_IN_QUEUE.put(message);
Log.v(TAG, "received: " + message);
} catch (Exception e) {
Logger.log("AsyncTaskSocketServer: Exception while writing to IN_QUEUE");
}
}
}
http服务器android的第一个结果:http://code.google.com/p/i-jetty/
您基本上可以做到这一点,但如果没有root,您将无法绑定特权端口(如端口80),也无法设置OOM杀手值来优先保护您的服务器,而不是其他可能需要内存的东西。
当然,除非上游wifi或3g提供商愿意给你一个可供感兴趣的客户路由的IP地址,否则你将无能为力。
Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...
Check this, List<String> list = new ArrayList<String>(); for (int i = 0; i < 10000; i++) { String value = (""+UUID.randomUUID().getLeastSignificantBits()).substring(3, ...
I am in the middle of solving a problem where I think it s best suited for a decorator and a state pattern. The high level setting is something like a sandwich maker and dispenser, where I have a set ...
I have been trying to execute a MS SQL Server stored procedure via JDBC today and have been unsuccessful thus far. The stored procedure has 1 input and 1 output parameter. With every combination I ...
I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...
If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...
I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....
I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...