How to create nanohttpd server in android?

后端 未结 4 1507
情话喂你
情话喂你 2021-02-09 05:10

Actually ,I had searched some questions and go to the github. But I\'m new ,I cannot understand the example.

I want to create the http server in android so I can access

4条回答
  •  无人及你
    2021-02-09 05:50

    Your sample code is missing one small detail - you create the server but you never call the "start()" method which kicks it off to listen for incoming connections. In your main() method, you could write

            (new MyHTTPD()).start();
    

    and all would be well, your server would respond the way you hoped it would.

    The reason it works that way is twofold: I want the constructor to be a cheap, inexpensive operation, without side-effects. For instance, while unit testing, I call "start()" in the setup and "stop()" in the teardown methods of my jUnit test.

提交回复
热议问题