forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebSocketApp.java
More file actions
32 lines (27 loc) · 756 Bytes
/
Copy pathWebSocketApp.java
File metadata and controls
32 lines (27 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* Jooby https://jooby.io
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
* Copyright 2014 Edgar Espina
*/
package examples;
import io.jooby.Jooby;
import java.nio.file.Paths;
public class WebSocketApp extends Jooby {
{
assets("/?*", Paths.get(System.getProperty("user.dir"), "examples", "www", "websocket"));
ws("/ws", (ctx, initializer) -> {
initializer.onConnect(ws -> {
ws.send("Welcome");
});
initializer.onMessage((ws, msg) -> {
ws.send("Got: " + msg.value());
});
initializer.onClose((ws, closeStatus) -> {
getLog().info("Closing with: {}", closeStatus);
});
});
}
public static void main(String[] args) {
runApp(args, WebSocketApp::new);
}
}