At my current customer we use TROIndyTCPChannel and TROBinMessage internally, because this is the fastest option.
Websockets in Delphi
Because RO does not have websocket support (yet), I tried to make a Proof of Concept (PoC) to see if it is possible. I searched and tried some Delphi implementations, but one was old (Indy9, old websocket spec), otherone had no sourcecode yet (Indy10, no response on my mail so far), etc. I found one which is based on "synapse", which is also included in RO, namely "bauglir-websocket".I looked at how RO made their TRO***Server and TRO***Channel and made a simple implementation for websockets: uROWebsocketChannel.pas and uROWebsocketServer.pas. This was almost too easy :).
I tested this with a Delphi RO demo server and client (using the RO wizard) and: tada, it works! :).
RO websocket channel
Next I had to make a websocket channel in "RemObjects for Javascript", and after some copy and paste I added this to the end of the RemObjectsSDK.js file. I made a simple html test file and this one works too!Node.js
Okay, what can we do next? Make a websocket server in html? Hmm, websockets (in html) can only make client connections and cannot act as a server...Maybe I can use it in Node.js? Note: Node.js is a server side javascript implementation, based on the Google V8 Javascript engine.
I found a websocket chat demo in Node.js, so it should be possible... Because it is not easy to debug in Node.js, I tried to make it work in Google Chrome first, by using the "websocket.onmessage" event and by sending a fetched JSON string (using the network debug tab in Chrome) when the html page connects to my Delphi server. After some hacking I could read the RO message, do the "sum" and send the data back to the client. Sweet!
After some little more hacking I also had it working in Node.js! So both my html page and my Delphi client can connect to the Node.js server. Ain't that cool! :)
Download and test
If you want to test it yourself, you can download the zip file, and do the following:- start "ROWebSocketsServer.exe"
- start "ROWebSocketsClient.exe" and open "\client\client.html"
- push the sum buttons, both should work
- stop "ROWebSocketsServer.exe"
- start the node.js server via "\node\start RO.node.bat"
- push the sum buttons in the clients (maybe restart them?), both should work too :)
8 opmerkingen:
Very cool! Thanks!
Delphi on Rails have builtin (opensource) WebSocket support.
I have tried Delphi on Rails without luck... now I am using sgcWebSockets works very well for me.
Hi André,
You said you use TROIndyTCPChannel and TROBinMessage, because this is the fastest option.
We are also using this approach with RemObjects. But, recently, while trying to solve some performance issues we found that WinInetHTTPChannel performs faster than IndyTCP, even when using binary data as TMemDataTable.
Have you ever benchmarked TROIndyTCPChannel against other Channels?
(FYI, we are using Delphi 7 + Indy 9 + RO SDK 5.0.35.741)
Thank you in advance.
Hi Lenin,
I only did some profiling with other channels (mail, http, winmessage, pipes, etc) a couple of years ago. But not between the several RO tcp channel (indy, synapse, wininit, etc).
Thanks for the idea, I will take a look at it soon too. But for now, our tcp+bin is performing good enough (D2010, Indy 10, Win7), I only had to force disable the nagle to remove the auto 200ms delay by Windows on small tcp messages :(
Hi André
I am searching for examples for WebSocket-Communication with Delphi
and would like to make a test with DelphiXE6 and Indy10. But your
link for downloading the demo is not working anymore.
Is it possible to download it anywhere else?
Thank you in advance.
Arthur
I moved the code to github, so it should be somewhere here now:
https://github.com/andremussche/AndrewsDelphiStuff/tree/master/-Other-/ROWebsocketsNode
Een reactie posten