https://github.com/levelrin/jws-server
A framework for WebSocket server in Java
https://github.com/levelrin/jws-server
java websocket websockets
Last synced: 5 months ago
JSON representation
A framework for WebSocket server in Java
- Host: GitHub
- URL: https://github.com/levelrin/jws-server
- Owner: levelrin
- License: mit
- Created: 2020-11-22T17:25:37.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-10-17T20:08:10.000Z (over 4 years ago)
- Last Synced: 2026-01-11T18:35:36.412Z (5 months ago)
- Topics: java, websocket, websockets
- Language: Java
- Homepage:
- Size: 268 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://circleci.com/gh/levelrin/jws-server)
[](https://codecov.io/github/levelrin/jws-server?branch=main)
[](https://maven-badges.herokuapp.com/maven-central/com.levelrin/jws-server)
[](https://github.com/levelrin/jws-server)
[](https://github.com/levelrin/jws-server/blob/main/LICENSE)
# jws-server
jws stands for Java WebSocket.
It is a Java library for building a WebSocket server.
It supports [rfc6455](https://datatracker.ietf.org/doc/html/rfc6455).
## Quick Start
Put the code below on your main method.
```java
new JwsGuide()
.defaultServerThread()
// default port is 42069 ;)
.defaultPort()
.defaultSocketThread()
.skipHostValidation()
.ignorePong()
.reaction(
// You should create your class that implements Reaction interface.
new Reaction() {
@Override
public String endpoint() {
// This reaction belongs to the '/yoi' endpoint.
return "/yoi";
}
@Override
public void onStart(final Session session) {
// This method will be called
// when WebSocket communication starts.
}
@Override
public void onMessage(final Session session, final String message) {
// This method will be called
// when you receive a text message from the client.
session.sendMessage("A message (reply) to the client.");
}
@Override
public void onMessage(final Session session, final byte[] message) {
// This method will be called
// when you receive a message from the client in bytes.
}
@Override
public void onClose(final Session session, final int code, final String reason) {
// This method will be called
// when WebSocket communication is about to be closed
// for that session.
}
}
).reaction(
// You can have multiple reactions like this.
new MoreReaction()
).ready().go();
```
Connect to your server like this (JavaScript):
```javascript
const socket = new WebSocket('ws://localhost:42069/yoi');
```
## Dependency
You just need to add the dependency like so:
Gradle:
```groovy
dependencies {
implementation 'com.levelrin:jws-server:0.1.0'
}
```
Maven:
```xml
com.levelrin
jws-server
0.1.0
```
Requirements:
1. JDK 1.15+
## How to contribute?
1. Create a [ticket](https://github.com/levelrin/jws-server/issues).
2. Send a [pull request](https://github.com/levelrin/jws-server/pulls).
Before you do that, run `./gradlew build` and make sure the build is clean.