-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WebSocket: An experimental websocket implementation!
- Loading branch information
Showing
8 changed files
with
811 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Casterlabs Commons/WebSocket | ||
|
||
An experimental WebSocket implementation. Not recommended for production use as this currently doesn't strictly adhere to the spec. | ||
|
||
## Examples | ||
|
||
```java | ||
WebSocketClient client = new WebSocketClient(URI.create("wss://echo.casterlabs.co")); | ||
client.setListener(new WebSocketListener() { | ||
@SneakyThrows | ||
@Override | ||
public void onOpen(WebSocketClient client, Map<String, String> headers, @Nullable String acceptedProtocol) { | ||
System.out.println("Connected. Headers: " + headers); | ||
} | ||
|
||
@Override | ||
public void onText(WebSocketClient client, String string) { | ||
System.out.println("Got text message: '" + string + "'"); | ||
} | ||
|
||
@Override | ||
public void onBinary(WebSocketClient client, byte[] bytes) { | ||
System.out.println("Got binary message: len=" + bytes.length); | ||
} | ||
|
||
@Override | ||
public void onClosed(WebSocketClient client) { | ||
System.out.println("Closed"); | ||
} | ||
}); | ||
client.connect(); | ||
|
||
Scanner in = new Scanner(System.in); | ||
while (true) { | ||
client.send(in.nextLine()); | ||
} | ||
|
||
// Type into the console to send messages to the server. It will echo them back :^) | ||
``` | ||
|
||
## Adding to your project | ||
|
||
Replace `VERSION_OR_HASH` with the latest version or commit in this repo and make sure to add the [Repository](https://github.com/Casterlabs/Commons#Repository) to your build system. | ||
|
||
<details> | ||
<summary>Maven</summary> | ||
|
||
```xml | ||
<dependency> | ||
<groupId>co.casterlabs.commons</groupId> | ||
<artifactId>websocket</artifactId> | ||
<version>VERSION_OR_HASH</version> | ||
</dependency> | ||
``` | ||
</details> | ||
|
||
<details> | ||
<summary>Gradle</summary> | ||
|
||
```gradle | ||
dependencies { | ||
implementation 'co.casterlabs.commons:websocket:VERSION_OR_HASH' | ||
} | ||
``` | ||
</details> | ||
|
||
<details> | ||
<summary>SBT</summary> | ||
|
||
``` | ||
libraryDependencies += "co.casterlabs.commons" % "websocket" % "VERSION_OR_HASH" | ||
``` | ||
</details> | ||
|
||
<details> | ||
<summary>Leiningen</summary> | ||
|
||
``` | ||
:dependencies [[co.casterlabs.commons/websocket "VERSION_OR_HASH"]] | ||
``` | ||
</details> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>websocket</artifactId> | ||
|
||
<parent> | ||
<groupId>co.casterlabs.commons</groupId> | ||
<artifactId>commons</artifactId> | ||
<version>PLACEHOLDER</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>co.casterlabs.commons</groupId> | ||
<artifactId>io</artifactId> | ||
<version>${project.parent.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
Oops, something went wrong.