Android作为Webservice Server?

问题描述

| 也许与其他人相反,我正在考虑在Android上运行网络服务服务器。有图书馆支持吗?我认为ksoap2例如仅用于使用Web服务,而不用于提供Web服务,对吗? 而且,如果没有冗长的编码不可能做到这一点,我只需要在Android上运行HTTP Server并接收二进制文件(通过POST)即可。 有人可以给些提示吗? 干杯, 渣     

解决方法

        最后,我放弃了在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地址,否则您将无法做很多事情。