You are not logged in.
Pages: 1
Hi,
using
aWebSocketServer := THttpApiWebSocketServer.Create(False);
aWebSocketServer.AddUrlWebSocket(aServerRoot, WebSocketsPort, ServerSecurity = secSSL, '*', True);
aWebSocketServer.RegisterProtocol(aProtocolName, False, OnAccept, OnMessage, OnConnect, OnDisconnect);
and connecting to it from a browser client like
socket = new WebSocket(`wss://domain:8081/Test/`, 'protocol')
socket.onopen = _message => {
console.log(_message)
socket.send(JSON.stringify(['mediator', { register: true, service: 'xyz', channels: 'xyz', id:' blubb' }])
}
socket.onmessage = _message => { console.log(_message) }
socket.onerror = _message => { console.log(_message) }
socket.onclose = _message => { console.log(_message) }
works perfectly.
However, how could I connect from a Delphi client to the web sockets (used for push notifications), as I do from the browser? Which mORMot-class should I use. All samples I've found directly use interfaces, and similar.
Last edited by sakura (2020-02-17 07:23:19)
Offline
You can use the lower level WebSockets connection.
Something like:
fWebSockets := THttpClientWebSockets.Create;
if doWebSocketsLog in fOptions then
WebSocketLog := TSynLog;
fWebSockets.Open(fServerURI, '80'); // use port 80 until our client supports TLS
if doWebSocketsLogVerbose in fOptions then
fWebSockets.Settings.SetFullLog;
proto := TWebSocketProtocolChat.Create(fWebSocketsProtocolName, '', OnFrameReceived);
msg := fWebSockets.WebSocketsUpgrade(fWebSocketsUri, '', false, false, proto);
if msg = '' then
log.Log(sllTrace, 'ConnectToWebSockets: upgraded with protocol %', [fWebSocketsProtocolName], self)
else
raise ESynException.CreateUTF8('WebSocketsUpgrade: %', [msg]);
Offline
Pages: 1