Android:System.err(1052)on

时间:2014-03-13 12:54:09

标签: android http handle httpservice

我有一个Web服务器(从服务启动):

public class WebServer extends Thread {

    private boolean isRunning = false;
    protected Context context = null;
    private int serverPort;

    private BasicHttpProcessor httpproc = null;
    private BasicHttpContext httpContext = null;
    private HttpService httpService = null;
    protected HttpRequestHandlerRegistry registry = null;
    private NotificationManager notifyManager = null;

    public WebServer(Context context, NotificationManager notifyManager, String serverName, int serverPort) {
        super(serverName);
        this.setContext(context);
        this.setNotifyManager(notifyManager);
        this.serverPort = serverPort;

//      SharedPreferences pref =
//              PreferenceManager.getDefaultSharedPreferences(context);

        this.httpproc = new BasicHttpProcessor();
        this.httpContext = new BasicHttpContext();

        this.httpproc.addInterceptor(new ResponseDate());
        this.httpproc.addInterceptor(new ResponseServer());
        this.httpproc.addInterceptor(new ResponseContent());
        this.httpproc.addInterceptor(new ResponseConnControl());

        this.httpService =
                new HttpService(this.httpproc, new DefaultConnectionReuseStrategy(),
                        new DefaultHttpResponseFactory());

        this.registry = new HttpRequestHandlerRegistry();

        setHandlerRegistry();
        this.httpService.setHandlerResolver(this.registry);
    }

    protected void setHandlerRegistry() {}

    @Override
    public void run() {
        super.run();

        try {
            ServerSocket serverSocket = new ServerSocket(this.serverPort);

            serverSocket.setReuseAddress(true);

            while (this.isRunning) {
                try {
                    final Socket socket = serverSocket.accept();

                    DefaultHttpServerConnection serverConnection =
                            new DefaultHttpServerConnection();

                    serverConnection.bind(socket, new BasicHttpParams());

                    this.httpService.handleRequest(serverConnection, this.httpContext);

                    serverConnection.shutdown();
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
                catch (HttpException e) {
                    e.printStackTrace();
                }
            }

            serverSocket.close();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }

有时,当我从客户端收到一些数据时,会为此代码行记录一条错误消息(跟踪);这个错误是随机的:

  this.httpService.handleRequest(serverConnection, this.httpContext);

错误消息是: W / System.err(1052)at ....

谢谢你们!

0 个答案:

没有答案