Giter Club home page Giter Club logo

coapblaster's Issues

How test the soapBluster library?

I managed to build a soapBluster project, but I don’t know how to test and use it. I created a java gradle project in IntelliJ IDEA, and added dependences according to the your recommendation to the build.gradle file. Also some changes were added to function main of Main.java class:

import com.google.iot.m2m.LocalEndpointManager;
import com.google.iot.m2m.Client;
import com.google.iot.m2m.Transaction;
import com.google.iot.m2m.Message;

public class Main {

    public static void main(String[] args)
    {
        System.out.println("Hello coap!");

        LocalEndpointManager manager = new LocalEndpointManager();

        Client client = new Client(manager, "coap://coap.me/test");

        Transaction transaction = client.newRequestBuilder().send();

        Message response = transaction.getResponse();

        System.out.println("Got response: " + response);
    }

}

However, apart from compilation errors, I received nothing:

Information:java: Errors occurred while compiling module 'testCoapBluster.testCoap.main'
Information:javac 1.8.0_201 was used to compile java sources
Information:2/28/19 9:42 AM - Compilation completed with 10 errors and 0 warnings in 1 s 635 ms
/home/michael_k/IdeaProjects/testCoap/src/main/java/Main.java
Error:(1, 26) java: package com.google.iot.m2m does not exist
Error:(2, 26) java: package com.google.iot.m2m does not exist
Error:(3, 26) java: package com.google.iot.m2m does not exist
Error:(4, 26) java: package com.google.iot.m2m does not exist
Error:(12, 9) java: cannot find symbol
  symbol:   class LocalEndpointManager
  location: class Main
Error:(12, 44) java: cannot find symbol
  symbol:   class LocalEndpointManager
  location: class Main
Error:(14, 9) java: cannot find symbol
  symbol:   class Client
  location: class Main
Error:(14, 29) java: cannot find symbol
  symbol:   class Client
  location: class Main
Error:(16, 9) java: cannot find symbol
  symbol:   class Transaction
  location: class Main
Error:(18, 9) java: cannot find symbol
  symbol:   class Message
  location: class Main

What is the matter and how to fix errors?

File build.gradle:

plugins {
    id 'java'
}

group 'testCoapBluster'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile 'com.google.iot.coap:coap:0.01.00'
}


Client-Server app doesn't work on Android.

I tried to test CoapBlaster on my phone. I wrote a simple application with two buttons: the first creates and starts the server, the second creates a client and tries to get a response:

public class MainActivity extends AppCompatActivity {
    final String TAG = "coap";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final Button server = findViewById(R.id.server);
        server.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startServer();
            }
        });

        final Button client = findViewById(R.id.client);
        client.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startClient();
            }
        });
    }

    private void startClient() {
        try {
            LocalEndpointManager manager = new LocalEndpointManager();
            Client client = new Client(manager, "coap://127.0.0.1/test/hello");
            Transaction transaction = client.newRequestBuilder().send();
            Message response = transaction.getResponse(5000);
            Log.e(TAG, "Got response: " + response.getPayloadAsString());
        }
        catch (Exception exception) {
            Log.e(TAG, "Client.Exception->" + exception.toString());
        }
    }

    private void startServer() {
        try {
            LocalEndpointManager manager = new LocalEndpointManager();
            Server server = new Server(manager);
            LocalEndpoint udpEndpoint = manager.getLocalEndpointForScheme(Coap.SCHEME_UDP);
            server.addLocalEndpoint(udpEndpoint);
            Resource<InboundRequestHandler> rootResource = new Resource<>();
            Resource<InboundRequestHandler> testFolder = new Resource<>();
            InboundRequestHandler helloHandler = new InboundRequestHandler() {
                public void onInboundRequest(InboundRequest inboundRequest) {
                    inboundRequest.sendSimpleResponse(Code.RESPONSE_CONTENT, "Hello, World!");
                }
            };
            testFolder.addChild("hello", helloHandler);
            rootResource.addChild("test", testFolder);
            server.setRequestHandler(rootResource);
            server.start();
            Log.e(TAG, "Server started");
        }
        catch (Exception exception) {
            Log.e(TAG, "Server.Exception->" + exception.toString());
        }
    }
}


Result:
2020-10-21 13:24:04.466 17315-17315/com.mk.testcoap2 E/coap: Server started
2020-10-21 13:24:12.968 17315-17315/com.mk.testcoap2 E/coap: Client.Exception->java.util.concurrent.TimeoutException
What's wrong?

Stop using coap.me in unit tests

Currently there are a few unit tests which actually use coap://coap.me, which isn't really a great idea long-term. This issue is tracking the replacement of those unit tests with more robust tests that don't rely on internet access nor burden third-party services.

Client Server Sample Program

Hello Team

I've tried client server sample program given in examples.

When I start server, not sure on which URI it is coming up and may be because of that client program is not able to make a connection to server URI.

My observation is ' client is not identifying where server is running' and I could not find an option where to fix host & port for server & client program.

@darconeous : Please advise. I've attached sample server & client program.

Thanks
coap.zip

Stop using Doclava

Doclava is currently used for Javadoc generation because it supports @hide, which is currently in use to hide experimental methods and classes from the Javadocs. Ultimately the real solution is to not use @hide, but this will require some refactoring of code.

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.