• Post Reply Bookmark Topic Watch Topic
  • New Topic

Program just doesn't seem to run as it should?  RSS feed

 
Don Joe
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been working with nanohttpd in Android quite a bit lately and decided to put together a straight up java app using it as well. I must confess this is my first java application outside of Android. I downloaded the community edition of IntelliJ IDEA and installed it. I went with this IDE because I have been using Android Studio. I created a new project based on the command line template as my intent was to create a web only interface for the app. I moved over my copy of nanohttpd.java and created an extension class just as I have done while using it in Android (of course omitting Android specific code). The app builds without errors however, when I run/debug it, the web server does not seem to run. It seems that the beginDaemon() method within nanohttpd does not start and maintain the running thread. Is there something that I have not done in the setup of the IDE? dependencies? When using nanohttpd in Android Studio, it was create new project, drop in class, crank out some code and it just worked? I have tested some code bits such as creating files, println() etc. and all seem to function. I have tried to post the relevant code below. When I run or debug I get the following in the console:

Connected to the target VM, address: '127.0.0.1:60358', transport: 'socket'
Server created
Disconnected from the target VM, address: '127.0.0.1:60358', transport: 'socket'
Process finished with exit code 0

TestApp.java

WebServer.java

NanoHttpd.java
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where does the NanoHttpd class come into play - does WebServer extend it?
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The implication of making a thread a daemon thread (line 23) is that it does not prevent the JVM from exiting normally.
When the main thread has run its course the daemon thread you created will not stop the program from terminating right then and there.
 
Don Joe
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Where does the NanoHttpd class come into play - does WebServer extend it?


yes, the WebServer class extends it.
 
Don Joe
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jelle Klap wrote:The implication of making a thread a daemon thread (line 23) is that it does not prevent the JVM from exiting normally.
When the main thread has run its course the daemon thread you created will not stop the program from terminating right then and there.


So in other words, I need to keep the main thread running. I guess by the nature of Android, it was doing this for me??
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That depends on how you ran it on Android - Android apps have a very different lifecycle than Java desktop apps.
 
Don Joe
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the info guys. I have another aspect of the program that maintains an open socket connection for communication. I have since successfully implemented this and thus my main thread continues to run, now the webserver seems to be functioning as it should. I guess I was under the impression that the daemon thread would keep everything running?? Yep, I'm a Java noob!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!