Websockets with Indy

Hi,

I have to implement a simple Websockets server to send some
notifications to a webbrowser application (Javascript).

I found different implementations in the Web with Indy/Delphi (free
and comercial). Is there somebody who worked with this and can confirm
which one works fine with all common browsers?

cu Christian
0
Christian
2/1/2014 2:30:48 PM
embarcadero.delphi.winsock 1874 articles. 2 followers. Follow

8 Replies
7801 Views

Similar Articles

[PageSpeed] 33

I am the author of this library (indy 10):
https://github.com/andremussche/DelphiWebsockets

I use it for several projects and works like a charm with at least Chrome.

btw: I can really recommend to use the socket.io library on top of it! Websocket itself is very plain and simple,
and socket.io has support for events, callbacks, etc
0
andre
2/4/2014 8:26:50 PM
>I am the author of this library (indy 10):
>https://github.com/andremussche/DelphiWebsockets
>
>I use it for several projects and works like a charm with at least Chrome.

Thanks. Works fine with Chrome and IE 11. But the same script fails
with Firefox. The Javascript I use is here:

<!DOCTYPE html>
  <meta charset="utf-8" />  
  <title>WebSocket Test</title>  
  <script language="javascript" type="text/javascript">  

    var wsUri = "ws://localhost:5099/"; 
    var output;  
    
    function init() { 
      output = document.getElementById("output"); 
      testWebSocket(); 
    }  
    
    function testWebSocket() { 
      websocket = new WebSocket(wsUri); 
      websocket.onopen = function(evt) { onOpen(evt) }; 
      websocket.onclose = function(evt) { onClose(evt) }; 
      websocket.onmessage = function(evt) { onMessage(evt) }; 
      websocket.onerror = function(evt) { onError(evt) }; 
    }  
    
    function onOpen(evt) { 
      writeToScreen("CONNECTED"); 
      doSend("WebSocket rocks"); 
    }  
    
    function onClose(evt) { 
      writeToScreen("DISCONNECTED"); 
    }  
    
    function onMessage(evt) { 
      writeToScreen('<span style="color: blue;">RESPONSE: ' +
evt.data+'</span>'); 
    }  
    
    function onError(evt) { 
      writeToScreen('<span style="color: red;">ERROR:</span> ' +
evt.data); 
    }  
    
    function doSend(message) { 
      writeToScreen("SENT: " + message);  
      websocket.send(message); 
    }  
    
    function writeToScreen(message) { 
      var pre = document.createElement("p"); 
      pre.style.wordWrap = "break-word"; 
      pre.innerHTML = message; 
      output.appendChild(pre); 
    }  
    
    window.addEventListener("load", init, false);  

  </script>  
  
  <h2>WebSocket Test</h2>  

  <div id="output"></div>  
  
</html>
    

cu Christian
0
Christian
2/8/2014 9:53:56 PM
andre mussche <> schrieb:

>I am the author of this library (indy 10):
>https://github.com/andremussche/DelphiWebsockets

I have one more question.

From the browser I have to use "ws://localhost:5099/" to connect to my
server. I plan to use the socket for messages only and have a regular
http server to get other data.

In my Delphi App I cannot activate a TIdHttpServer on the same port as
the TIdWebsocketServer. But if I try to call "http://localhost:5099/"
with the TIdWebSocketServer component only, I don't get any data and
the DoCommandGet method is never called.

I would like to handle socket connections / http calls on the same
server/port. Is this not possible?

cu Christian
0
Christian
2/8/2014 10:05:53 PM
> Thanks. Works fine with Chrome and IE 11. But the same script fails
> with Firefox. The Javascript I use is here:

Just a note - your code works fine in all browsers with WebSockets server of our SecureBlackbox ( https://www.eldos.com/sbb/ ).
0
Eugene
2/10/2014 9:32:23 AM
> I would like to handle socket connections / http calls on the same
> server/port. Is this not possible?

yes of course is this possible! This was the main reason I made it :)
One port to rule them all:
- plain http server (for files .js/.html/.css)
- low level plain websockets
- event driven socket.io 
- and RemObjects handling (http channel and own websocket channel)

I updated the unit test, so take a look at it if it still doesn't work for you
0
andre
2/10/2014 10:34:02 AM
> {quote:title=Christian Kaufmann wrote:}{quote}
> Thanks. Works fine with Chrome and IE 11. But the same script fails
> with Firefox...

Fixed
When you run dunit (in debug mode) and do a selected start of "create objects" + "start server" + "plain http" you can load your test page using this url:
http://localhost:8099/html/wstest.html

(note: I added your test page in the \win32\debug\html folder)
0
andre
2/10/2014 10:51:18 AM
>yes of course is this possible! This was the main reason I made it :)
>One port to rule them all:

Ok. Seems to work. I just replaced my TIdHttpServer with
TIdWebsocketServer and it looks like all works like before.
Is there a difference regarding performance?

And a question for the method TIdWebsocketServer.SendMessageToAll():
Here you loop over all Contexts. Are these all TIdServerWSContext
objects even if it happens to be a context from another running
regular HTTP request?

cu Christian
0
Christian
2/10/2014 8:08:01 PM
> {quote:title=Christian Kaufmann wrote:}{quote}
> Ok. Seems to work. I just replaced my TIdHttpServer with
> TIdWebsocketServer and it looks like all works like before.
> Is there a difference regarding performance?

should be the same
it only checks if a context is "websocket" or "socket.io" otherwise it uses the
normal handling (not the fastest but good enough for normal use)
 
> And a question for the method TIdWebsocketServer.SendMessageToAll():
> Here you loop over all Contexts. Are these all TIdServerWSContext
> objects even if it happens to be a context from another running
> regular HTTP request?

it only sends to context where "IsWebsocket" is true, so it won't send 
messages to normal http GET contexts etc
0
andre
2/10/2014 8:14:19 PM
Reply:

Similar Artilces:

Converting Delphi 2007 Indy 10.2.3 to Delphi 2009 Indy 10.5.5 [Edit]
Hello, I am currently attempting to port over a Delphi 2007 project that uses Indy 10.2.3 (very successfully) to Delphi 2009 and Indy 10.5.5 (I just got the latest development build this morning). I think I am running into an encoding issue, but am not sure. Specifically, IDHTTP with SSL calls an old CGI and the CGI returns a .zip file and I then save it to the disk. In 2007 and before this worked perfectly. In 2009, it is not. Here is the examples of the 2 different results (though cut way short in the post) I am getting back: 2007: 'PK'#3#4#$14#0#0#0#8#0'rLQ9žrPb€'#0...

delphi 7 Indy 9 and Indy 10
Hi, I can upgrade to indy 10 in delphi 7. But I have discover that indy 9 and Indy 10 have some different properties, so i had to change my old programs that were made in indy 9 to upgrade it to new version, but it is a long work. So I want to know if it is possible to install in the same delphi 7 both versions indy 10 and indy 9. I have tried to do it but i received a error message: Cannot load package 'IndySystem70'. It contains unit 'IdWinSock2', which is also contained in package 'Indy70'. Some can give me ideas or a link to read how to install both versi...

Indy WebSockets
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --JivePart=_7a127.zeB8CwDOH5aMJzMl Content-Type: text/plain; charset="Utf-8" Attached is a zip file containing two Delphi 2009 websocket demos per RFC 6455 as mentioned in the thread titled "Indy WebSockets" posted in embarcadero.public.delphi.internet.winsock. The first one, WSock, implements a websocket connection on localhost port 81 using a TIdTCPServer component. To run, check the Online box and then manually load the...

Indy E-Mail Problem (Indy 10, Delphi 2007)
Hello, we use Indy 10 with Delphi 2007 to get E-Mail using IMAP. We recieved an E-Mail which is not handled correctly. The E-Mail looks like this {code} Return-Path: <test@mail.com>; From: "Test Tester" <test@mail.com>; To: <test@mail.com>; Subject: Order Date: Wed, 7 Mar 2012 16:50:40 +0100 Message-ID: <15D526BEB8091D43859549D9E16E370FBA3123> MIME-Version: 1.0 Content-Type: text/html; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQFk6K6fcF3...

Indy IdHMACSHA1 different results in Delphi 2007 and Delphi 2009
Hello newsgroup A test of the IdHMACSHA1 encryption method shows different results, and I am not sure if there is an error in my code or in the Indy code shipped with Delphi 2009. The Delphi 2007 version works in an application which communicates with Amazon Web Services and so it seems to be the correct one. Any suggestions are very welcome, maybe I just need to download a newer version of Indy? program Test; {$APPTYPE CONSOLE} uses IdHMACSHA1, IdCoderMIME, IdGlobal, SysUtils; function Base64Encode(const Input: string): string; begin Result := TIdEncode...

Indy WebSockets
It's been awhile since I've updated my Indy components. Is there an official Indy WebSocket component available yet or plans to produce one? I've been looking at RFC 6455 and managed to make a crude Websocket chat app using the TidTCPServer component. What I really want is a component that can do both HTTP and Websocket connections simultaneously so that the client can do everything through port 80. By the way, I'm aware of the WebSocket component available from www.esegece.com but it does not act as an HTTP server. I could attempt to expand what I've alr...

migrating from Delphi 6 With Indy 10 to XE7 with Indy 10
I updated the original Indy in D6 to version 10 several years ago. Now I want to migrate my application from D6 to XE7 and would like some feedback on the best route to take. I usually send data using readln and writeln statements. The data is typically XML format. Since migrating to XE7 will include potential unicode data what is the best approach to take when reading and writing data? Will writeln and readln work in these cases or should I be using a different strategy to send unicode data between the tidtcpclient and tidtcpserver applications? al wrote: > I usually send data ...

Delphi 7, Indy
I am trying to learn to use the Indy components with D7. I'm using the book "Mastering Delphi 7". I can't follow his examples, and below is a couple of excerpts that I need help with. The first relates to a form with a TIdTCPClient component on it. He indicates the following: object IdTCPServer1: TIdTCPServer defaultPort = 1050 end Is he indicating that the property should be set to 1050, or is this some type of code? If so, I'm lost. I would appreciate some help Another puzzler is object IdTCPServer1: TIdTCPServer CommandHandler...

Delphi 2009 and Indy
I installed Delphi 2009. As far as I can see Indy 10 is installed with it. Now I try to get a program working that I made under Delphi 7. It uses TIDHashMessageDigest. Now I cannot use it because of a undeclared identifier. I added IDGlobal, IDHash, IDHashMessageDigest to the uses list, but no result. What went wrong, maybe something with installation? Please help. Franklin Bockstael wrote: > > What went wrong, maybe something with installation? No, I suspect that it has something to do with Indy. I'd suggest asking in one of the technical groups that covers ...

Indy and Delphi 2009 ???
Hello All, Please forgive me if this question has been answered and well documented, but I can't seem to locate the info! :) Is anyone using Indy 10 with Delphi 2009? If so, any problems with the unicode change, etc? TIA -- David David Saracini wrote: > Is anyone using Indy 10 with Delphi 2009? Yes > If so, any problems with the unicode change, etc? Just a couple. If you do have a specific question try here: embarcadero.public.delphi.internet.winsock or any Indy group on the atozed server: news.atozedsoftware.com -- Pieter "One o...

Indy support and Delphi
Hi all, I've been off the support site for nearly a year since the move to Embarcadero. Does anyone know where to get help with an Indy/Delphi 5 issue ? I was ready to pay the Indy team to help but they have shut down support ... wont even do it for money. I have an issue with the POP3 server that is showing up and need some short technical advise. TIA, Del Delbert Murray schrieb: > Hi all, > I've been off the support site for nearly a year since the move to > Embarcadero. Does anyone know where to get help with an Indy/Delphi 5 issue > ? I was ready to pay ...

How to upgrade Indy in Delphi 2009
Hi, Delphi 2009 comes with Indy 10.2.5, but because there is a bug with email attachments, I need to upgrade to the latest version of Indy (10.5.7 ?). The installation instructions are on the Indy website : [http://www.indyproject.org/Sockets/Docs/Indy10Installation.EN.aspx |http://www.indyproject.org/Sockets/Docs/Indy10Installation.EN.aspx ] But they are not clear to me. Does anyone know the exact procedure ? Thanks Herman <PC Support> wrote in message news:265626@forums.embarcadero.com... > The installation instructions are on the Indy website : > [http://...

Upgrading Indy in Delphi 2009
Hello, I'm in the process of upgrading the version of Indy 10 provided with Delphi 2009 (inorder to resolve the bug with email attachments). I've got the latest code "Indy10_4454.zip" from "http://indy.fulgan.com/ZIP/" and I've managed to track down some basic instructions on how to uninstall and then reinstall Indy but there seems to be some conflict as to wether I should be using the "dcl__120.dpk's" or the "dcl__130.dpk's". I can see that the 120's are currently installed in Delphi 2009 (which I believe is Delphi v12)...

Indy Samples for Delphi XE
Where can I find Indy samples for Delphi XE. I don't see them installed on my PC. I would like to have some NEW samples, not from 2004. If anyone could help I would appreciate it. Thanks. Mihaela. "Mihaela Mihaljevic Jakic" <mihaela@token.hr> wrote in message news:415451@forums.embarcadero.com... > Where can I find Indy samples for Delphi XE. I don't see > them installed on my PC. I would like to have some NEW > samples, not from 2004. If anyone could help I would > appreciate it. There are no Indy demos installed with the IDE. The Indy...

Web resources about - Websockets with Indy - embarcadero.delphi.winsock

Real-Time Web Test - Does your browser supports WebSockets?
This test was created to study implications of using WebSockets and Comet in real-life scenarios. Having WebSockets supported in your browser ...

WebSocket.org A WebSocket Community
The WebSocket specification—developed as part of the HTML5 initiative—introduced the WebSocket JavaScript interface, which defines a full-duplex ...

WebSocket - realtime communication for the Web
WebSocket is a new standard for realtime communication on the web. WebSocket defines a simple JavaScript API and accompanying protocol that allows ...

WebSocket - Wikipedia, the free encyclopedia
WebSocket is a web technology providing full-duplex communications channels over a single TCP connection. The WebSocket API is being standardized ...

HTML5 Standards WebSocket, Shared Worker Fuel Facebook Messenger For Firefox’s Social API
Facebook Software Developer Pamela Vagata offered a behind-the-scenes look at the creation of Facebook Messenger for Firefox’s Social API in ...

WebSocket Applications and Vision for the Future - YouTube
We rarely talk about the actual mechanics of how we develop webapps, but in this session from HTML5DevConf, we'll get into some new techniques ...

Apple adds accelerometer, WebSockets support to Safari in iOS 4.2
description With the release of iOS 4.2 for the iPhone and iPad, Apple has added WebSockets and accelerometer support in the Mobile Safari Web ...

WebSockets: A Glimpse of the Future
... of the future, servers must be able to transparently push data to clients. People have been trying to do this for a long time, and WebSockets ...

CEX.IO Presents WebSocket API for Professional Traders
Press Release: CEX.IO has developed a real-time WebSocket API, a tool for professional traders, providing the fastest way to obtain data from ...

Kaazing WebSocket Gateway Pushes Offline iPhone Data
Less power and less data means longer battery life in mobile devices

Resources last updated: 1/23/2016 2:45:09 AM