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

How to call WebSockets directly via Java?

Explorer ,
Oct 28, 2019 Oct 28, 2019

In order to enable WebSockets, the following example is given:

 

application.cfc

 

this.name = "WebSocketDemo"; this.wschannels = [{name="stocks"},{name="chat"}];

 

When application variables are dumped, this.name looks like it gets translated into application.applicationname.  However, wschannels is nowhere to be found.  How would one be able to enable websockets via a call in application.cfm or any cfm page?

 

I tried this but neither worked:

 

<cfset application.wschannels = [{name="stocks"},{name="chat"}]>

<cfset application.this.wschannels = [{name="stocks"},{name="chat"}]>

TOPICS
Advanced techniques
419
Translate
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 ,
Oct 28, 2019 Oct 28, 2019

// The application name (this setting is not for the websocket).. 

this.name = "WebSocketDemo";

// You must include the listener (CFC) of a websocket. 

this.wschannels = [{name="stocks",cfclistener="stockListener"},{name="chat",cfclistener="chatListener"}];

 

Example: ChatListener.cfc

component extends="CFIDE.websocket.ChannelListener"
{
  public boolean function allowSubscribe(Struct subscriberInfo)
   {
     if(structKeyExists(subscriberInfo,"utype"))
       {
        //Validating if a user has publish right & adding a new key to ConnectionInfo 
          if(subscriberInfo.utype eq "Moderator" or subscriberInfo.utype eq "Member" ){
              subscriberInfo.connectioninfo.havepublishright=true;
              return true;
          } else {
              subscriberInfo.connectioninfo.havepublishright=false;
              return false;
          }
       
       }
   }
  
   public boolean function allowPublish(Struct publisherInfo)
   {
       if(structKeyExists(publisherInfo.connectioninfo,"havepublishright")){
         if(publisherInfo.connectioninfo.havepublishright){
            return true;
         } else {
            return false;
         }
       }
   }
 
}
Translate
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 ,
Oct 29, 2019 Oct 29, 2019

Thanks -- but I don't see how this would work in, say, an application.cfm file.  "this.wschannel" seems to only exist inside application.cfc -- or am I mistaken?

Translate
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 ,
Oct 29, 2019 Oct 29, 2019

I would advise you to use Application.cfc. Application.cfm is outdated.

But, to answer your question, Application.cfm may use something like

 

<cfapplication name="WebSocketDemo"
wschannels=[{name="stocks",cfclistener="stockListener"},{name="chat",cfclistener="chatListener"}]
clientmanagement="No"
sessionmanagement="Yes"
sessionTimeout=createTimespan(0,0,30,0)>
Translate
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 ,
Oct 31, 2019 Oct 31, 2019

No go...

 

Attribute validation error for tag CFAPPLICATION.

It does not allow the attribute(s) WSCHANNELS. The valid attribute(s) are APPLICATIONTIMEOUT,AUTHCOOKIE,CLIENTMANAGEMENT,CLIENTSTORAGE,COMPILEEXTFORINCLUDE,DATASOURCE,ENABLENULLSUPPORT,EXCHANGESERVERVERSION,LOGINSTORAGE,NAME,PASSARRAYBYREFERENCE,SAMEFORMFIELDSASARRAY,SCRIPTPROTECT,SEARCHIMPLICITSCOPES,SECUREJSON,SECUREJSONPREFIX,SERVERSIDEFORMVALIDATION,SESSIONCOOKIE,SESSIONMANAGEMENT,SESSIONTIMEOUT,SETCLIENTCOOKIES,SETDOMAINCOOKIES,STRICTNUMBERVALIDATION,WSVERSION.

 

WSCHANNEL doesn't work, either...

Translate
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 ,
Oct 31, 2019 Oct 31, 2019
LATEST

That can only mean that the ColdFusion team didn't consider it worthwhile to include the attribute wschannel to the cfapplication tag. They generally do their best to ensure that new additions to Application.cfc are backward-compatible with Application.cfm. Hence my assumption. But, unfortunately, not in this case.

 

As I said earlier, Application.cfm is outdated. You should continue with your original idea to use Application.cfc.

 

In any case, I have answered your original question. The Application.cfm issue arises from a new question. If you feel strongly about the absence of the wschannel attribute in <cfapplication>, report a bug. You might just get the ColdFusion team to include it.

Translate
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 ,
Oct 30, 2019 Oct 30, 2019

Please mark the correct answer. That will help someone else in future.

Translate
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