Erweiterungen
This commit is contained in:
@@ -32,14 +32,70 @@ Das System bietet folgende STOMP-Funktionalitäten:
|
||||
|
||||
```javascript
|
||||
// Mit SockJS
|
||||
const socket = new SockJS('http://localhost:8080/ws');
|
||||
const socket = new SockJS('http://192.168.180.196:8080/ws');
|
||||
const stompClient = Stomp.over(socket);
|
||||
|
||||
// Oder mit nativem WebSocket
|
||||
const socket = new WebSocket('ws://localhost:8080/websocket');
|
||||
// Oder mit nativem WebSocket (WICHTIG: ws:// verwenden, nicht http://)
|
||||
const socket = new WebSocket('ws://192.168.180.196:8080/websocket');
|
||||
const stompClient = Stomp.over(socket);
|
||||
```
|
||||
|
||||
### Flutter/Dart STOMP Client
|
||||
|
||||
**Für Flutter-Apps verwenden Sie diese Konfiguration:**
|
||||
|
||||
```dart
|
||||
import 'package:stomp_dart_client/stomp.dart';
|
||||
import 'package:stomp_dart_client/stomp_config.dart';
|
||||
import 'package:stomp_dart_client/stomp_frame.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
// WICHTIG: Verwenden Sie ws:// für WebSocket-Verbindungen, NICHT http://
|
||||
final stompClient = StompClient(
|
||||
config: StompConfig(
|
||||
url: 'ws://192.168.180.196:8080/websocket', // Beachten Sie ws:// statt http://
|
||||
onConnect: onConnectCallback,
|
||||
onWebSocketError: (dynamic error) => print('WebSocket Error: $error'),
|
||||
onStompError: (StompFrame frame) => print('Stomp Error: ${frame.body}'),
|
||||
onDisconnect: (StompFrame frame) => print('Disconnected'),
|
||||
// Heartbeat-Konfiguration
|
||||
heartbeatIncoming: Duration(seconds: 20),
|
||||
heartbeatOutgoing: Duration(seconds: 20),
|
||||
),
|
||||
);
|
||||
|
||||
void onConnectCallback(StompFrame frame) {
|
||||
print('Connected to STOMP server');
|
||||
|
||||
// Nachrichten abonnieren
|
||||
stompClient.subscribe(
|
||||
destination: '/topic/messages',
|
||||
callback: (StompFrame frame) {
|
||||
print('Received message: ${frame.body}');
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// Verbindung herstellen
|
||||
stompClient.activate();
|
||||
|
||||
// Nachricht senden
|
||||
void sendMessage(String content) {
|
||||
stompClient.send(
|
||||
destination: '/app/message',
|
||||
body: jsonEncode({
|
||||
'content': content,
|
||||
'sender': 'FlutterApp',
|
||||
}),
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
**Alternative Endpunkte für Flutter:**
|
||||
Falls Probleme mit `/websocket` auftreten, versuchen Sie:
|
||||
- `ws://192.168.180.196:8080/stomp` (zusätzlicher Endpunkt)
|
||||
- `ws://192.168.180.196:8080/ws` (SockJS-Endpunkt ohne SockJS-Protokoll)
|
||||
|
||||
### 2. Verbindung herstellen
|
||||
|
||||
```javascript
|
||||
|
||||
Reference in New Issue
Block a user