You are not logged in.
Hi,
I'm new of mORMot, now I try to build a application which receive the data from a web servers which use websockets as their method to delivery the data real time. Then I find that mORMot has some units which do many websockets works, so I would like to build my application base on the units of mORMot, Then after I looked all the demo of Samples 31, I see that all the websockets client implication base on the Interface with the mORMot websockets server. So I want to know if the units that I can build on them may create a websockets client application which can talk with the other websockets servers already built by others languages NOT base on the windows Interface technology?
I have tried some code and do not know how to do that, Can you help to get my test to work with the websockets site such as echo.websocket.org ? The demo server is https://www.websocket.org/echo.html .
Here I have some code, just get some errors with upgrade to websockets failed, What I need to add some raw header strings to get it to work?
procedure TForm2.Button6Click(Sender: TObject);
var Client: TSQLHttpClientWebsockets;
workName: string;
cmd, msg: SockString;
begin
Client := TSQLHttpClientWebsockets.Create('echo.websocket.org','80',TSQLModel.Create([]));
try
Client.Model.Owner := Client;
Client.WebSockets.Settings.SetFullLog;
// Client.WebSocketsUpgrade(PROJECT31_TRANSMISSION_KEY);
memo1.Lines.Add( Client.WebSocketsUpgrade('', true) );
try
memo1.Lines.Add(Client.WebSockets.Server);
if Client.WebSockets.SockConnected then
memo1.Lines.Add('SockConnected true');
Client.WebSockets.SockSend('Hello, websocket.org');
Client.WebSockets.SockSendFlush;
Client.WebSockets.SockRecvLn(msg);
memo1.Lines.Add(msg);
finally
//callback := nil;
//Service := nil; // release the service local instance BEFORE Client.Free
end;
finally
Client.Free;
end;
end;
Thank you.
Last edited by wqmeng (2017-09-29 15:22:21)
Offline
From the memo1, I get some result shows the upgrade failure,
Invalid HTTP Upgrade Header
echo.websocket.org
SockConnected true
<html><head></head><body><h1>404 WebSocket Upgrade Failure</h1></body></html>HTTP/1.1 501 Not Implemented
Offline
Hi, after review the code of Samples\31 - Project31ChatServer and Project31ChatClient, Do they implement the websockets standard? I think that they are not common websockets applications.
Offline
After change the
Client.WebSocketsUpgrade('', true)
to
Client.WebSockets.WebSocketsUpgrade('/?encoding=text', '')
Then, It seems that I can upgrade the client to a websockets connection. But I still get the error string 'Invalid HTTP Upgrade Header' ;
Here is I get result in memo1.
Invalid HTTP Upgrade Header
echo.websocket.org
SockConnected true
Connection: Upgrade
Date: Fri, 29 Sep 2017 15:19:00 GMT
Sec-WebSocket-Accept: PnZv2+arapwxuaf6vrXbBQYwBJc=
Server: Kaazing Gateway
Upgrade: websocket
Last edited by wqmeng (2017-09-29 15:22:48)
Offline
And I dump the headers to memo1.
for I := Low(Client.WebSockets.Headers) to High(Client.WebSockets.Headers) do begin
memo1.Lines.Add(Client.WebSockets.Headers[ I]);
end;
From the headers, it shows
Connection: Upgrade
Date: Fri, 29 Sep 2017 15:19:00 GMT
Sec-WebSocket-Accept: PnZv2+arapwxuaf6vrXbBQYwBJc=
Server: Kaazing Gateway
Upgrade: websocket
So, the client should be upgrade to be a websockets connection with echo.websocket.org .
Then I do know how to send message and receive the data from the server.
Last edited by wqmeng (2017-09-29 15:24:56)
Offline
After I watch the chrome connection to echo.websocket.org, from the data which show in the developer tools,
Now the echo.websocket.org server is waiting my client to send some headers to complete the handshake ?
Offline
General
Request URL:wss://echo.websocket.org/?encoding=text
Request Method:GET
Status Code:101 Web Socket Protocol Handshake
Response Headers
view source
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:x-websocket-protocol
Access-Control-Allow-Headers:x-websocket-version
Access-Control-Allow-Headers:x-websocket-extensions
Access-Control-Allow-Headers:authorization
Access-Control-Allow-Headers:content-type
Access-Control-Allow-Origin:https://www.websocket.org
Connection:Upgrade
Date:Fri, 29 Sep 2017 15:49:54 GMT
Sec-WebSocket-Accept:N+kpt4PQBw7C/MeTZPzLHON+AeA=
Server:Kaazing Gateway
Upgrade:websocket
Request Headers
view source
Accept-Encoding:gzip, deflate, br
Accept-Language:zh-CN,zh;q=0.8
Cache-Control:no-cache
Connection:Upgrade
Cookie:__zlcmid=ikgmcydUmlJ7z4; _ga=GA1.2.1394516097.1506699313; _gid=GA1.2.814511308.1506699313; _gat=1
Host:echo.websocket.org
Origin:https://www.websocket.org
Pragma:no-cache
Sec-WebSocket-Extensions:permessage-deflate; client_max_window_bits
Sec-WebSocket-Key:ML8U6aK3xJQQTgdKUaHjlQ==
Sec-WebSocket-Version:13
Upgrade:websocket
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
Query String Parameters
view source
view URL encoded
encoding:text
Offline
I added some new code try to send a frame to the server, but when I trace the code and get some access violation errors when ProcessMask , not sure why.
protocol := TWebSocketProtocolChat.Create('meow', '');
process := TMyWebSocketProcessClient.Create(Client.WebSockets, protocol, 'mORMotWebsocketClientProcess');
//Client.WebSockets.WebSockets:= process;
//process := Client.WebSockets.WebSockets;
frame.opcode := TWebSocketFrameOpCode.focText;
frame.content := [];
frame.payload := 'hello, test chat!';
if process.SendFrame(frame) then begin
memo1.lines.add('send frame success');
end;
The problem code is
PCardinalArray(data)^[i] := PCardinalArray(data)^[i] xor mask;
And SendFrame fail.
Offline
Hello AB,
Are you interesting this and can help with this? Websockets is popular now and mostly the wesockets servers are node.js or other python servers, so that we can use client part in Delphi to deal with them.
And big thank you for sharing the nice framework. Will try to learn more of it.
Offline
You are mixing things up here.
1. wss:// is for WebSockets over TLS, which are not supported directly yet by the framework (you need a TLS proxy like nginx above it).
2. If you want raw WebSockets with node.js or python servers, use raw WebSockets support, as with Project31SimpleEchoServer.dpr.
Interface-based websockets WON'T work directly with python or node.js.
Offline
Hello AB,
1, The wss is from the Chrome capture data, and My first aim is to get the ws:// without TLS to work.
2, I checked out the Project31SimpleEchoServer.dpr, It is the server part, You see my code posted here which try to get the client part to work, but not work out yet. As you focus on the interface implement, so that if I want to get a client to connect a Node.js server, I will need to work from the client standard webSockets protocol?
Thank you very much.
Offline