Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ic4j/ic4j-websocket
https://github.com/ic4j/ic4j-websocket
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/ic4j/ic4j-websocket
- Owner: ic4j
- License: apache-2.0
- Created: 2023-08-21T11:32:06.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-06-03T11:32:14.000Z (5 months ago)
- Last Synced: 2024-08-02T06:15:33.406Z (3 months ago)
- Language: Java
- Size: 215 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-internet-computer - ic4j-websocket - Library for for interfacing with the IC via WebSocket using Java (Android compatible). (Client Libraries (Agents) / Java)
README
## IC4J Websocket Client
This Java library implements the ICP Websocket Gateway protocol, allowing any Java application to receive Websocket messages from ICP smart contracts.
https://github.com/omnia-network/ic-websocket-gateway
# Build
You need JDK 8+ to build IC4J Websocket Agent.
# License
IC4J Websocket is available under Apache License 2.0.
# Documentation
```
KeyPair keyPair = KeyPairGenerator.getInstance("Ed25519").generateKeyPair();BasicIdentity identity = BasicIdentity.fromKeyPair(keyPair);
ReplicaTransport httpTransport = ReplicaOkHttpTransport.create(env.getProperty("ic.location"));
final WebsocketTransport wsTransport = new JavaxWebsocketTransport(new URI(env.getProperty("ws.location")), httpTransport);
WsAgent wsAgent = new WsAgent( Principal.fromString(env.getProperty("ic.canister")),
wsTransport, identity).setLocal(Boolean.parseBoolean(env.getProperty("local","false")));
wsAgent
.addMessageHandler((output) -> {
try {
AppMessage result = IDLArgs.fromBytes(output).getArgs().get(0).getValue(new PojoDeserializer(), AppMessage.class);
LOG.info(result.text);
AppMessage response = new AppMessage();
response.text = "Pong";
response.timestamp = System.currentTimeMillis();
byte[] payload = WsAgent.encodeValue(response);
wsAgent.sendApplicationMessage(payload);
} catch (Exception e) {
LOG.error(e.getLocalizedMessage(),e);
}
});wsAgent.start();
// wait 100 seconds for messages from websocket
Thread.sleep(100000);
wsAgent.close();
```# Downloads / Accessing Binaries
To add IC4J Websocket library to your Java project use Maven or Gradle import from Maven Central.
https://search.maven.org/artifact/org.ic4j/ic4j-websocket/0.7.0/jar```
org.ic4j
ic4j-websocket
0.7.0```
```
implementation 'org.ic4j:ic4j-websocket:0.7.0'
```