Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How are nanolets intended to be used? #482

Open
benfrancis opened this issue Feb 24, 2018 · 7 comments
Open

How are nanolets intended to be used? #482

benfrancis opened this issue Feb 24, 2018 · 7 comments

Comments

@benfrancis
Copy link

I had the same question as #287. How are nanolets intended to be used? Are you really supposed to manually copy and paste the RouterNanoHTTPD class into your project?

Could this be documented somewhere? I haven't been able to figure out how to use nanolets using the unit tests as reference as suggested in the README.

I'm using gradle and guessed at using "router" as an artifact ID:

compile([group: 'org.nanohttpd', name: 'router', version: '2.3.1'])

But it failed to resolve.

Thank you

@benfrancis
Copy link
Author

benfrancis commented Feb 24, 2018

Aha, I think the artifact ID is nanohttpd-nanolets.

compile([group: 'org.nanohttpd', name: 'nanohttpd', version: '2.3.1'])
compile([group: 'org.nanohttpd', name: 'nanohttpd-nanolets', version: '2.3.1'])

@benfrancis
Copy link
Author

Having managed to import RouterNanoHTTPD using gradle as above, I created a class which extends RouterNanoHTTPD and tried to run it using ServerRunner as in the AppNanolets.java example:

ServerRunner.run(MyServerClass.class);

ServerRunner appears to start the server, but then it immediately stops again:

Server started, Hit Enter to stop.
Server stopped.

Is this because the example is expected to be run from the command line and some command line arguments are missing? I'm trying to embed the server in an Android app and execute it directly with ServerRunner.

@benfrancis
Copy link
Author

Just leaving a note to say that I had more success by calling MyServerClass.start() directly:

        try {
            server = new MyServerClass();
        } catch (IOException e) {
            System.out.println("Failed to instantiate MyServerClass");
        }

        try {
            server.start();
        } catch (IOException e) {
            System.out.println("MyServerClass failed to start");
        }

Now to muddle through and figure out which methods to override to create my routes. Some more documentation on this would definitely be appreciated!

@h0jeZvgoxFepBQ2C
Copy link

Yeah, same question here.. A bit more documentation for the nanolets would be helpfull... Great software anyway!! Thanks!

@LordFokas
Copy link
Member

Nanolets, IIRC, are intended to work as plug-in pieces of software than handle requests. You make your whole application into one nanolet, and then plug it into a working nanolets server and it suddenly works (the same way you drop, say, a whole PHP site in an Apache+PHP docs folder), the difference being it's a lot safer and more performant, and you can run several different applications at once with little to no interference. I don't know much more about it though, since my role here is mostly core and protocols (HTTP and WS is pretty much everything I've been doing)

@vnnv
Copy link
Contributor

vnnv commented Mar 5, 2018

I'll try to find free time and add some documentation or example as the original work is mine.

@vikascn
Copy link

vikascn commented Jun 4, 2019

@vnnv did you get a chance make an example yet ? I am trying to run this on Android as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants