{"id":19316850,"url":"https://github.com/atmosphere/wasync","last_synced_at":"2025-05-15T22:09:37.933Z","repository":{"id":2893020,"uuid":"3900538","full_name":"Atmosphere/wasync","owner":"Atmosphere","description":"WebSockets with fallback transports client library for Node.js, Android and Java","archived":false,"fork":false,"pushed_at":"2025-01-21T16:22:12.000Z","size":4492,"stargazers_count":160,"open_issues_count":26,"forks_count":44,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-05-15T22:08:56.029Z","etag":null,"topics":["atmosphere","java","nodejs","websockets"],"latest_commit_sha":null,"homepage":"http://async-io.org","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Atmosphere.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-2.0.txt","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":"2012-04-02T12:49:19.000Z","updated_at":"2025-03-04T00:37:59.000Z","dependencies_parsed_at":"2025-02-02T14:11:19.228Z","dependency_job_id":"99652b09-c243-4e46-890d-9f8f7899f2af","html_url":"https://github.com/Atmosphere/wasync","commit_stats":{"total_commits":562,"total_committers":24,"mean_commits":"23.416666666666668","dds":"0.17971530249110323","last_synced_commit":"6ba81a5b02c2ef0ab02c9081d93049f8b2317621"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atmosphere%2Fwasync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atmosphere%2Fwasync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atmosphere%2Fwasync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atmosphere%2Fwasync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Atmosphere","download_url":"https://codeload.github.com/Atmosphere/wasync/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254430330,"owners_count":22069909,"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":["atmosphere","java","nodejs","websockets"],"created_at":"2024-11-10T01:12:54.712Z","updated_at":"2025-05-15T22:09:37.869Z","avatar_url":"https://github.com/Atmosphere.png","language":"Java","readme":"## wAsync: A WebSockets/HTTP Client Library for Asynchronous Communication\n\nwAsync is a Java based library allowing asynchronous communication with any WebServer supporting the WebSocket or Http Protocol.\nwAsync can be used with Node.js, Android, Atmosphere or any WebSocket Framework. To get started, read this super simple [Tutorial](https://github.com/Atmosphere/wasync/wiki/Getting-Started-with-wAsync)\nor read the [FAQ](https://github.com/Atmosphere/wasync/wiki/FAQ)\n\nYou can browse the [javadoc](http://atmosphere.github.io/wasync/apidocs/) or browse our [samples](https://github.com/Atmosphere/atmosphere-samples/tree/master/wasync-samples).\n\nYou can [download the jar](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22wasync%22) or use Maven\n```xml\n          \u003cdependency\u003e\n              \u003cgroupId\u003eorg.atmosphere\u003c/groupId\u003e\n              \u003cartifactId\u003ewasync\u003c/artifactId\u003e\n              \u003cversion\u003e3.0.2\u003c/version\u003e\n          \u003c/dependency\u003e\n```\nAs simple as\n\n```java\n        Client client = ClientFactory.getDefault().newClient();\n\n        RequestBuilder request = client.newRequestBuilder()\n                .method(Request.METHOD.GET)\n                .uri(\"http://async-io.org\")\n                .encoder(new Encoder\u003cString, Reader\u003e() {        // Stream the request body\n                    @Override\n                    public Reader encode(String s) {\n                        return new StringReader(s);\n                    }\n                })\n                .decoder(new Decoder\u003cString, Reader\u003e() {\n                    @Override\n                    public Reader decode(Event type, String s) {\n                        return new StringReader(s);\n                    }\n                })\n                .transport(Request.TRANSPORT.WEBSOCKET)                        // Try WebSocket\n                .transport(Request.TRANSPORT.LONG_POLLING);                    // Fallback to Long-Polling\n\n        Socket socket = client.create();\n        socket.on(new Function\u003cReader\u003e() {\n            @Override\n            public void on(Reader r) {\n                // Read the response\n            }\n        }).on(new Function\u003cIOException\u003e() {\n\n            @Override\n            public void on(IOException ioe) {\n                // Some IOException occurred\n            }\n\n        }).open(request.build())\n            .fire(\"echo\")\n            .fire(\"bong\");\n```\nLife cycle of the underlying Socket can easily be implemented as well\n```java\n\n           Socket socket = client.create();\n           socket.on(Event.CLOSE.name(), new Function\u003cString\u003e() {\n               @Override\n               public void on(String t) {\n               }\n           }).on(Event.REOPENED.name(), new Function\u003cString\u003e() {\n               @Override\n               public void on(String t) {\n               }\n           }).on(new Function\u003cIOException\u003e() {\n               @Override\n               public void on(IOException ioe) {\n                   ioe.printStackTrace();\n               }\n           }).on(Event.OPEN.name(), new Function\u003cString\u003e() {\n               @Override\n               public void on(String t) {\n               }\n           }).open(request.build());\n```\n\nYou can also use the specialized clients. For example, to transparently enable Atmosphere's Protocol\n\n```java\n       AtmosphereClient client = ClientFactory.getDefault().newClient(AtmosphereClient.class);\n\n       RequestBuilder request = client.newRequestBuilder()\n    \t\t   .method(Request.METHOD.GET)\n    \t\t   .uri(targetUrl + \"/suspend\")\n               .trackMessageLength(true)\n    \t\t   .transport(Request.TRANSPORT.LONG_POLLING);\n```\n\nor if you want to serialize the fire() method call so events are asynchronously sent in the order the fire method is called\n\n```java\n        SerializedClient client = ClientFactory.getDefault().newClient(SerializedClient.class);\n\n        SerializedOptionsBuilder b = client.newOptionsBuilder();\n        b.serializedFireStage(new DefaultSerializedFireStage());\n\n        RequestBuilder request = client.newRequestBuilder()\n                .method(Request.METHOD.GET)\n                .uri(targetUrl + \"/suspend\")\n                .transport(Request.TRANSPORT.WEBSOCKET);\n\n        Socket socket = client.create(b.build());\n```\n\nBy default, the [FunctionResolver](http://atmosphere.github.io/wasync/apidocs/org/atmosphere/wasync/FunctionResolver.html) will associate the Decoder's type will be used to invoke the appropriate Function, if defined. For\nexample,\n\n```java\n   Decoder\u003cString, POJO\u003e d = new Decoder\u003cString, POJO\u003e() {\n             @Override\n             public POJO decode(Event type, String s) {\n                 if (type.equals(Event.MESSAGE)) {\n                    return new POJO(s);\n                 } else {\n                    return s;\n                 }\n             }\n         }\n```\nwill be associated to\n```java\n   Function\u003cString\u003e f = new Function\u003cPOJO\u003e() {\n             @Override\n             public void on(POJO t) {\n\n             }\n        }\n```\nYou can also implement your own FunctionResolver to associate the Function with Decoder\n```java\n         Socket socket = client.create();\n         socket.on(\"myEvent\", new Function\u003cReader\u003e() { ...}\n```\nwhere myEvent could be read from the response's body.\n\nWant to write an Android Client? [See](http://jfarcand.wordpress.com/2013/04/04/wasync-websockets-with-fallbacks-transports-for-android-node-js-and-atmosphere/)\n\n\n#### Build Status\n[![Build Status](https://api.travis-ci.org/Atmosphere/wasync.svg?branch=master)](https://travis-ci.org/Atmosphere/wasync)\n\n[![Analytics](https://ga-beacon.appspot.com/UA-31990725-2/Atmosphere/wasync)]\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatmosphere%2Fwasync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatmosphere%2Fwasync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatmosphere%2Fwasync/lists"}