• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Connect to Websocket using cf11

New Here ,
Sep 22, 2021 Sep 22, 2021

Copy link to clipboard

Copied

Hi,

 

I need to consume the bitstamp websocket ( wss://ws.bitstamp.net. ) using ColdFusion and process the stream in the backend. I have read the cfwebsocket documentation, however this focuses on creating a websocket, i just want to consume an external websocket and process. Much the same as using cfhttp to make an API call. Any example code would be very much appreciated.    

Link to bitstamp documentation 

 https://www.bitstamp.net/websocket/v2/

Views

249

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 24, 2021 Sep 24, 2021

Copy link to clipboard

Copied

I should leave others with more experience to comment on making outbound websocket API calls from CF. But in case no one offers anything, I do have two thoughts (one being an attempted answer, and the other being a possible alternative for you). 

 

But again others with more experience may help me see my first answer here is incorrect or incomplete.

 

1) My sense is that it will NOT work--because websockets generally establish an asynchronous connection, and typically rely on event handling (built into the browser and enabled via js, when it's acting as a party  to a websocket connection), and the support in CF's websocket specifically send that js to the browser.

 

As such, the question would be how CF would perform such asynch event handling. It CAN do such async event handling (various ways), but I'm just saying I don't think Adobe ever built in the SPECIFIC support needed to make things work when the websocket calls are to a websocket partner that is NOT a browser.

 

Again, I could be wrong. It could be that somehow the websocket feature DOES provide for this--since technically websocket comm is two way, and CF would need to be able to "handle the event" of a client sending it a message--once a connection is established using the CF websocket feature. I just don't see  how to enable it (from the reading I've done of various resources on CF websockets, as it seems you have seen also), though perhaps it's there somewhere.

 

2) But before you may give up on a hope of connecting to bitstamp, I see that those docs you link to offer an http api (https://www.bitstamp.net/api/), as perhaps you already noticed. And of course you COULD just call that via cfhttp and CF's support of json deserialization/serialization. But maybe you prefer websocket for the asserted "real-time" character that the bitstamp site says is an advantage of the websockets approach. Even so, if you can't get that, maybe the http approach will suffice.

 

Again, let's see if perhaps others may have different thoughts.


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 24, 2021 Sep 24, 2021

Copy link to clipboard

Copied

I've also reached out privately to Giancarlo Gomez, who is the OG on CF websocket use, asking if he could join in here or even just offer me a quick thought on whether I was on the right track in my reply.


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 24, 2021 Sep 24, 2021

Copy link to clipboard

Copied

Hello, this is really not possble from the backend as an active client is required to create the WebSocket connection and respond the to the onmessage WebSocket API event. What I recommend, if you want realtime messages and not poll their REST API, is to create a middleman page. A basic webpage that connects to their API and on the onmessage event you post the data received ( or what you need from it ) to your ColdFusion server.  Then you simply open that page and keep it running on any browser. There might be a way to do this with headless chrome ( if you don't want to manually open a browser ), but I believe the work involved for that has no real benefit if it is to just to connect to this one service and that middleman page would still need to be coded. 

I hope my responses are clear and didn't cause more confusion. The cfwebsocket tag is basically a way to connect from a client to the ColdFusion WebSocket server. It is not meant for server to server, it is for client to server and of course the page that runs it is on the ColdFusion server that it is connecting to. In the simplest explanation, it includes JavaScript libraries on the rendered page that allows for that connectivity.


Giancarlo Gomez aka "JC"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 24, 2021 Sep 24, 2021

Copy link to clipboard

Copied

Thanks very much for the confirmation, JC. 


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 25, 2021 Sep 25, 2021

Copy link to clipboard

Copied

Hi Charlie, Giancarlo,

Thanks for the update, been working with CF since 4.5 and was really stuck here. Indeed it was the realtime stream I was after to build an order engine. Looks like polling the API will be the way forward. 

Thanks again. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 27, 2021 Sep 27, 2021

Copy link to clipboard

Copied

LATEST

Happy to help 🙂


Giancarlo Gomez aka "JC"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 27, 2021 Sep 27, 2021

Copy link to clipboard

Copied

You're welcome Charlie!


Giancarlo Gomez aka "JC"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation