Question

I am coding a message distribution system. Server is ColdFusion (CF) 10, using the new <cfwebsocket> feature set. Client will be written in Delphi 2009.

If I write the client in ColdFusion (using the <cfwebsocket> tag) things work fine: I can send messages between two clients. So the server side appears to be working.

No such luck with a Delphi client. I've tried two component libraries so far (Delphi on Rails and sgcWebSockets). Both seem to establish a connection to the CF server, but messages are not sent or received. I'm fairly certain Delphi is making a connection to the server as no exceptions are thrown if I specify the correct address, whereas I get an exception if I specify a different port or URI.

I think the missing link is in my understanding of "channels". It's easy in CF: you specify the channel to subscribe to or send messages to and it works. But the concept of "channels" doesn't seem to exist much outside of ColdFusion. I've searched w3.org, Google, etc, and don't see much about channels in the HTML5 WebSocket specs. Some references, but nothing clear, especially in the examples.

In summary, my questions:

  1. Are "channels" part of the standard WebSocket API, and if so,
  2. How do I subscribe to a channel using one of the Delphi WebSocket libraries I mentioned? Shouldn't it be as easy as ws://[server]:[port]/[channel]?
  3. How to debug WebSocket connections & traffic on the CF server?

Many thanks. This is my first post on StackOverflow; apologies if it's a tad long.

Était-ce utile?

La solution 3

Thanks for the tips! I have done a bit of debugging since I posted the question and have discovered some answers.

Are "channels" part of the standard WebSocket API?

From what I can tell, no. Channels appear to be a ColdFusion-specific concept.

How do I subscribe to a channel using one of the Delphi WebSocket libraries I mentioned? Shouldn't it be as easy as ws://[server]:[port]/[channel]?

As mentioned in my original question, Delphi (using the TsgcWebSocketClient component) was connecting successfully to the ColdFusion (CF) WebSocket server. However, I found I was omitting a step: subscribing to the CF "channel". I discovered this by using Microsoft Network Monitor to compare the Delphi client traffic to the CF client traffic. The CF client was sending an additional string to the server after connecting:

{"ns":"coldfusion.websocket.channels","type":"welcome","authKey":"6DD10C406710970271EDA2295C409D38","subscribeTo":"signals","appName":"Test"}

This subscribes the client to the "signals" channel. So, I added the following line to my Delphi code after a connection was made:

sgcWebSocketClient.WriteData( '{"ns":"Delphi","type":"welcome","authKey":"6DD10C406710970271EDA2295C409D38","subscribeTo":"signals","appName":"Test"}' );

and the Delphi client was immediately able to receive messages from the CF "signals" channel.

FYI, here is how to send a message ("Hello, World!" in this case) from the Delphi client to the "signals" channel:

sgcWebSocketClient.WriteData( {"ns":"Delphi","type":"publish","channel":"signals","data":"Hello, World!","appName":"Test"}

How to debug WebSocket connections & traffic on the CF server?

I found Microsoft Network Monitor, with a port filter applied, was the easiest method. It does not currently support loopback/localhost monitoring, so I used another computer on our LAN to generate the traffic.

Autres conseils

I using (or trying/investigating) this websocket implementation: http://code.google.com/p/bauglir-websocket/

I don't know ColdFusion, also the "channels" part is not what I know of websockets. Has CF a web client? Then you can debug it easily in Google Chrome

This is not really an answer, but a troubleshooting suggestion. Disclosure: I come from a CF background, but have not looked at the websocket implementation yet, so this is just generic advice, and how I'd go about troubleshooting this.

It might be worth looking at the HTTP & WS traffic between client and server on a CF-created client, to see where the channel name fits into things. I scoured the web socket spec, and I too could find nothing that seemed to equate to "channels".

From my reading of the websocket spec, as far as I can tell, one URI = one "channel": there's no scope for more than one channel (or "feed" perhaps) on a URI. From a CF perspective maybe - and this is complete speculation - this "channel" concept is a trick by CF to be able to track more than one websocket service on a single URI? CF bends over backwards (to the point of tumbling over, sometimes) to try to make life "easier" for the CF developers, so I could see them doing this. Or simply they just decided to implement their own way, not thinking that the client end might not be implemented with CF's libraries too.

Editorial material aside: check what's going on in the HTTP & WS packets going between client and server, and I imagine you'll be able to work out WTH CF is doing.

I tried this online demo: http://www.raymondcamden.com/demos/2012/feb/19/chat/#

When I place a breakpoint in the "function msgHandler" (Google Chrome, inspect element, script tab) I get the following data:

Object
channel: "chat"
clientid: 692538231
code: 0
msg: "ok"
ns: "coldfusion.websocket.channels"
reqType: "getSubscriberCount"
subscriberCount: 1
type: "response"
__proto__: Object

However, when I try another demo: http://www.raymondcamden.com/demos/2012/feb/19/whiteboard/ it gives this data:

Object
channelname: "whiteboard"
data: Object
ns: "coldfusion.websocket.channels"
publisherid: 692539350
type: "data"
__proto__: Object

At least I see some "channel" stuff in it. So you probably should make your own JSON object (as string) with some of the above properties.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top