Coder Social home page Coder Social logo

Comments (4)

mhatrepratik11 avatar mhatrepratik11 commented on July 25, 2024

I was able to solve client registration issue with below code:

final LeshanClient client = leshanClientBuilder
			.setEndpointsProviders(new CaliforniumClientEndpointsProvider.Builder().build())
			.build();

Setting clientAddress to CaliforniumClientEndpointsProvider was my mistake: "endpointsBuilder.setClientAddress(InetAddress.getLocalHost());"
With this change the client is working fine now.

So now only issue persist is of Leshan WebServer UI is not working at http://localhost:8080
I have added below code for WebServer.

// Starting jetty webserver for UI at http://localhost:8080
InetSocketAddress jettyAddr = new InetSocketAddress("127.0.0.1", 8080);
Server jettyServer = new Server(jettyAddr);
jettyServer.start();

Any suggestions / help would be great.

Thank you for your attention!

from leshan.

sbernard31 avatar sbernard31 commented on July 25, 2024

I looked at your server code and it should rather looks like :

        // create provider
        final CaliforniumServerEndpointsProvider californiumServerEndpointsProvider = new CaliforniumServerEndpointsProvider.Builder(
                new CoapServerProtocolProvider()) //
                        .setConfiguration(config -> config.set(CoapConfig.PROTOCOL_STAGE_THREAD_COUNT, 4))
                        .addEndpoint("coap://localhost:5683") //
                        // OR
                        // .addEndpoint(new InetSocketAddress("localhost", 5683), Protocol.COAP) //
                        .build();

        // create server
        LeshanServerBuilder builder = new LeshanServerBuilder();
        // builder.setRegistrationIdProvider(new RandomStringRegistrationIdProvider()); // not needed used by default
        builder.setEndpointsProviders(californiumServerEndpointsProvider);
        LeshanServer server = builder.build();

        // start it
        server.start();

        // listen for registration
        server.getRegistrationService().addListener(new RegistrationListener() {
            @Override
            public void registered(Registration registration, Registration previousReg,
                    Collection<Observation> previousObservations) {
                System.out.println("Registered client: " + registration.getEndpoint());
            }
            // Other override methods
        });

     // All the jetty code is useless OR it missed your own code to add `Servlet` to jetty.

So now only issue persist is of Leshan WebServer UI is not working at http://localhost:8080/

Leshan is a library, there is no web server UI.
But Leshan provide a standalone demo which contains a web UI.

See FAQ to better understand : https://github.com/eclipse-leshan/leshan/wiki/F.A.Q.#what-is-leshan-and-how-should-i-use-it-
Maybe I should change again the README + FAQ, as it seems not clear for everybody 🤔

from leshan.

mhatrepratik11 avatar mhatrepratik11 commented on July 25, 2024

Thank you very much @sbernard31. Now it's clear to me and thanks for the code. I will change my code accordingly. Satisfied with the answer and good to close this issue. Thanks again...

from leshan.

sbernard31 avatar sbernard31 commented on July 25, 2024

You're welcome.

from leshan.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.