Explorar el Código

deux trois trucs

master
DemiSel hace 3 años
padre
commit
f4eacb68fb

+ 17
- 0
src/main/java/websockets/handlers/CuisineWebSocketReceiveHandler.java Ver fichero

@@ -0,0 +1,17 @@
1
+package websockets.handlers;
2
+
3
+import io.undertow.websockets.core.AbstractReceiveListener;
4
+import io.undertow.websockets.core.WebSocketChannel;
5
+
6
+public class CuisineReceiveListener extends AbstractReceiveListener {
7
+
8
+    public void register(WebSocketChannel iChannel)
9
+    {
10
+
11
+    }
12
+
13
+    public void unregister(WebSocketChannel iChannel)
14
+    {
15
+
16
+    }
17
+}

src/main/java/websockets/CuisineWebSocketChichatHandler.java → src/main/java/websockets/handlers/CuisineWebSocketWebSocketChichatHandler.java Ver fichero

@@ -1,4 +1,4 @@
1
-package websockets;
1
+package websockets.handlers;
2 2
 
3 3
 import io.undertow.websockets.core.AbstractReceiveListener;
4 4
 import io.undertow.websockets.core.BufferedTextMessage;
@@ -7,12 +7,12 @@ import io.undertow.websockets.core.WebSockets;
7 7
 
8 8
 import java.util.ArrayList;
9 9
 
10
-public class CuisineWebSocketChichatHandler extends AbstractReceiveListener {
10
+public class CuisineWebSocketChichatHandler extends CuisineReceiveListener {
11 11
 
12 12
     final int MAX_MESSAGES = 10;
13 13
     ArrayList<String> vMessageHistory;
14 14
 
15
-    protected CuisineWebSocketChichatHandler() {
15
+    public CuisineWebSocketChichatHandler() {
16 16
         vMessageHistory = new ArrayList<>();
17 17
     }
18 18
 
@@ -29,8 +29,23 @@ public class CuisineWebSocketChichatHandler extends AbstractReceiveListener {
29 29
         {
30 30
             vBuilder.append(vMessage+"\n");
31 31
         }
32
-        //Handle message on webSocket
32
+
33 33
         WebSockets.sendText(vBuilder.toString(), iChannel, null);
34 34
     }
35 35
 
36
+    public void register(WebSocketChannel iChannel)
37
+    {
38
+
39
+    }
40
+
41
+    public void unregister(WebSocketChannel iChannel)
42
+    {
43
+
44
+    }
45
+
46
+    protected void notifyOthers(String iMessages)
47
+    {
48
+        Websockets.sendText(iMessages)
49
+    }
50
+
36 51
 }

+ 22
- 0
src/main/java/websockets/handlers/CuisineWebSocketWebSocketTemperatureHandler.java Ver fichero

@@ -0,0 +1,22 @@
1
+package websockets.handlers;
2
+
3
+
4
+import io.undertow.websockets.core.BufferedTextMessage;
5
+import io.undertow.websockets.core.WebSocketChannel;
6
+import io.undertow.websockets.core.WebSockets;
7
+import tcp.CuisineTCPServer;
8
+
9
+public class CuisineWebSocketWebSocketMessageHandler extends CuisineWebSocketReceiveHandler {
10
+
11
+    private CuisineTCPServer fTCPServer;
12
+
13
+    public CuisineWebSocketWebSocketMessageHandler(CuisineTCPServer iTCPServer) {
14
+        super();
15
+        fTCPServer = iTCPServer;
16
+    }
17
+
18
+    protected void onFullTextMessage(WebSocketChannel iChannel, BufferedTextMessage iTextMessage) {
19
+        //Handle message on webSocket
20
+        WebSockets.sendText(String.valueOf(fTCPServer.getCurrentTemperature()), iChannel, null);
21
+    }
22
+}

Loading…
Cancelar
Guardar