{"id":13704998,"url":"https://github.com/PelionIoT/java-coap","last_synced_at":"2025-05-05T12:32:50.826Z","repository":{"id":39961910,"uuid":"89562636","full_name":"PelionIoT/java-coap","owner":"PelionIoT","description":"CoAP Java library","archived":false,"fork":false,"pushed_at":"2023-12-05T22:39:55.000Z","size":1139,"stargazers_count":70,"open_issues_count":5,"forks_count":34,"subscribers_count":18,"default_branch":"master","last_synced_at":"2024-05-20T00:15:23.816Z","etag":null,"topics":["coap","iot","java","java-coap","lwm2m","mbed"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PelionIoT.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-27T06:18:45.000Z","updated_at":"2024-08-02T23:22:52.076Z","dependencies_parsed_at":"2024-01-07T21:03:02.122Z","dependency_job_id":"39ff1b21-da2d-4ccf-8863-e6d54bf17381","html_url":"https://github.com/PelionIoT/java-coap","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PelionIoT%2Fjava-coap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PelionIoT%2Fjava-coap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PelionIoT%2Fjava-coap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PelionIoT%2Fjava-coap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PelionIoT","download_url":"https://codeload.github.com/PelionIoT/java-coap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252497718,"owners_count":21757670,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coap","iot","java","java-coap","lwm2m","mbed"],"created_at":"2024-08-02T22:00:29.513Z","updated_at":"2025-05-05T12:32:50.411Z","avatar_url":"https://github.com/PelionIoT.png","language":"Java","readme":"mbed CoAP\n=========\n\n![CircleCI](https://img.shields.io/circleci/project/github/PelionIoT/java-coap/master.svg)\n[![License](https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg)](LICENSE)\n[![codecov](https://codecov.io/gh/PelionIoT/java-coap/branch/master/graph/badge.svg)](https://codecov.io/gh/PelionIoT/java-coap)\n[![Known Vulnerabilities](https://snyk.io/test/github/PelionIoT/java-coap/badge.svg)](https://snyk.io/test/github/PelionIoT/java-coap)\n\nMaintenance\n-----------\nThis repository is under minimal maintenance.\nThere is a more actively developed version available at [https://github.com/open-coap/java-coap](https://github.com/open-coap/java-coap) - you might want to check that repository out.\nThere are API differences, though.\n\nIntroduction\n------------\n\nThis library makes it easy to integrate a Java SE enabled device with CoAP based services like [Izuma Networks Device Management](https://www.izumanetworks.com). \nIt can also help to emulate an embedded device for prototyping and testing purposes.\n\nThe following features are supported by the library:\n\n* Complete CoAP support\n    - The Constrained Application Protocol [RFC 7252](https://tools.ietf.org/html/rfc7252)\n    - Observing Resources in the Constrained Application Protocol [RFC 7641](https://tools.ietf.org/html/rfc7641)\n    - Block-Wise Transfers in the Constrained Application Protocol [RFC 7959](https://tools.ietf.org/html/rfc7959)\n* CoRE Link Format processing API\n    - Constrained RESTful Environments (CoRE) Link Format [RFC 6690](https://tools.ietf.org/html/rfc6690)\n* CoAP server mode\n* CoAP client mode\n* Coap over tcp, tls [RFC 8323](https://tools.ietf.org/html/rfc8323)\n    - excluding: websockets, observations with BERT blocks\n* Network transports:\n    - UDP (plain text)\n    - TCP (plain text)\n    - TLS\n* LwM2M TLV and JSON data formats\n\nRequirements\n------------\n\n### Runtime:\n\n* JRE 8\n* JRE 11\n\n### Development:\n\n* JDK 8\n* maven 3.x\n\n\nUsing the Library\n-----------------\n\nAdd repository to build file:\n\n    \u003crepositories\u003e\n\t\t\u003crepository\u003e\n\t\t    \u003cid\u003ejitpack.io\u003c/id\u003e\n\t\t    \u003curl\u003ehttps://jitpack.io\u003c/url\u003e\n\t\t\u003c/repository\u003e\n\t\u003c/repositories\u003e\n\nAdd dependency into your `pom.xml`:\n\n    \u003cdependency\u003e\n        \u003cgroupId\u003ecom.mbed.java-coap\u003c/groupId\u003e\n        \u003cartifactId\u003ecoap-core\u003c/artifactId\u003e\n        \u003cversion\u003e{VERSION}\u003c/version\u003e\n    \u003c/dependency\u003e\n\n\n### Creating a Server\n\n#### Initializing, starting and stopping the server\n\nTo initialize a server, you must at minimum define the port number. You must set the server parameters before starting a server. \n\n    CoapServer server = CoapServer.builder().transport(5683).build();\n    server.start();\n\nTo stop a server, use the `stop()` method.\n\t\n    server.stop();\n\n\n#### Adding request handlers\n\nYou can add handlers before or while the server is running. There can be several URI paths assigned to the same handler. \nYou can also remove a handler at any time.\n\n    CoapHandler handler = new ReadOnlyCoapResource(\"24\");\n    server.addRequestHandler(\"/temperature\", handler);\n    \n    server.removeRequestHandler(handler);\n\n\n\n#### Creating CoAP resources\n\nTo create a CoAP resource, you must implement a `CoapHandler`. There is one abstract helper class `CoapResource` that can be extended. At minimum, implement the `get()` method. \n\nThe following example overrides `get()` and `put()` and creates a simple CoAP resource:\n\n    public class SimpleCoapResource extends CoapResource {\n        private String body=\"Hello World\";\n        \n        @Override\n        public void get(CoapExchange ex) throws CoapCodeException {\n            ex.setResponseBody(\"Hello World\");\n            ex.setResponseCode(Code.C205_CONTENT);\n            ex.sendResponse();\n        }\n        \n        @Override\n        public void put(CoapExchange ex) throws CoapCodeException {\n          body = ex.getRequestBodyString();        \n            ex.setResponseCode(Code.C204_CHANGED);\n            ex.sendResponse();\n        }\n    }\n\n### Creating a client\n\n\nTo make a CoAP request, use the class `CoapClient`. It uses fluent API. The following is a simple example on the usage:\n\n    CoapClient client = CoapClientBuilder.newBuilder(new InetSocketAddress(\"localhost\",5683)).build();\n    \n    CoapPacket coapResp = client.resource(\"/s/temp\").sync().get();\n    \n    coapResp = client.resource(\"/a/relay\").payload(\"1\", MediaTypes.CT_TEXT_PLAIN).sync().put();\n        \n    //it is important to close connection in order to release socket\n    client.close();\n    \n\nExample client\n--------------\n\nThis [example client](example-client) demonstrates how to build coap client.\n\n\nDevelopment\n-----------\n\n### Issues with localhost on Ubuntu\n\nUbuntu has IP addresses for localhost, `127.0.0.1` and `127.0.1.1`.\nThis causes problems with CoAP packets, the request and response address does not match.\nChange both addresses to `127.0.0.1` or comment or remove the latter from `/etc/hosts` and change hostname to localhost.\n\nTo check hostname:\n\n```\n    hostname\n```\n\nTo change hostname to localhost:\n\n```\n    sudo hostname localhost\n```\n\n### Build\n\n    mvn clean install\n     \n### Build with all checks enabled\n     \n    mvn clean install -P ci\n\n### Update license header\n\n    mvn com.mycila:license-maven-plugin:format\n\nContributions\n-------------\n\nAll contributions are Apache 2.0. Only submit contributions where you have authored all of the code. If you do this on work time make sure your employer is OK with this.\n\nLicense\n-------\n\nUnless specifically indicated otherwise in a file, files are licensed under the Apache 2.0 license, \nas can be found in: [LICENSE](LICENSE)\n","funding_links":[],"categories":["Libraries"],"sub_categories":["Java"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPelionIoT%2Fjava-coap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FPelionIoT%2Fjava-coap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPelionIoT%2Fjava-coap/lists"}