B4J Question WebSocket - RunFunction

Discussion in 'B4J Questions' started by aaronk, May 26, 2015.

  1. aaronk

    aaronk Well-Known Member Licensed User

    Hi,

    Just wondering what the trick is to run the web socket RunFunction function?

    I have a function on my HTML page like:

    HTML:
    <script>
        jQuery(document).ready(function() {
            test();
        });
    
        function test(){
            alert("testing");
        }
    </script>
    When I run my HTML code it will alert 'testing' since it's calling that function on page load, which is fine while I am testing it.

    In my B4J app I am trying to call this function using a web socket like:

    Code:
    Sub btnCalc_Click (Params As Map)
      
        ws.RunFunction(
    "test"Null)
      
    End Sub
    The problem I have is when I run the app it comes up with the error:

    Code:
    Parsing code.                           0.05
    Compiling code.                         Error
    Error compiling program.
    Error description: Too many parameters.
    Occurred on line: 
    24
    ws.RunFunction(
    "test"Null)
    Word: _c
    From what I understand there is too many parameters in the RunFunction function part in my code.

    I tried doing:

    Code:
    Sub btnCalc_Click (Params As Map)
      
        ws.RunFunction(
    "test")
      
    End Sub
    Now when I run the app it says:

    Code:
    Parsing code.                           0.03
    Compiling code.                         Error
    Error compiling program.
    Error description: Missing parameter.
    Occurred on line: 
    24
    ws.RunFunction(
    "test")
    Word: )
    How can I trigger the JavaScript Function from a web Socket, is this the correct way in doing it ?
     
  2. billzhan

    billzhan Active Member Licensed User

    ws.RunFunction("test",Array As Object(Null))
     
  3. aaronk

    aaronk Well-Known Member Licensed User

    Still get the same error.

    Code:
    Parsing code.                           0.14
    Compiling code.                         Error
    Error compiling program.
    Error description: Too many parameters.
    Occurred on line: 
    24
    ws.RunFunction(
    "test",Array As Object(Null))
    Word: 
    array
    (Running this with B4J version 2.50)
     
  4. billzhan

    billzhan Active Member Licensed User

    I made simple test based on the webapp hello world demo. (b4j 2.5 &2.8)

    Code:
    ws.RunFunction("test"Null)  'working
    ws.RunFunction("test",Array As Object(Null))  'working
    Something else may cause this error
     

    Attached Files:

  5. Daestrum

    Daestrum Well-Known Member Licensed User

    Are you including the b4j_ws.js file in your page, and then on doc.ready calling b4j_connect("??") ?
     
  6. aaronk

    aaronk Well-Known Member Licensed User

    When I run your example it seems to work.
    I then copied your 'HelloWorld' module code into my project and it then comes up with the same error saying there isToo many parameters.


    Yes I have that in my www folder and am calling it.

    HTML:
    $( document ).ready(function() {
        b4j_connect("/ws");
    });
    The problem is that it won't compile the B4J app.

    There must be something else in my project that is causing this error and will need to now look through my other modules to see what might be the cause.
    At least I now know that it should work, and will now look into it and find out what the cause might be.
     
  7. aaronk

    aaronk Well-Known Member Licensed User

    Worked it out..

    In my Main Module I had the code:

    Code:
    Sub AppStart (Args() As String)
        srvr.Initialize(
    "srvr")
        srvr.AddWebSocket(
    "/ws""WebSocket")
        srvr.Port = 
    51042
        srvr.Start
        StartMessageLoop
    End Sub
    As you will see the Module it's going to use is 'WebSocket'

    Since in that module it's calling the WebSocket (Private ws As WebSocket) you can't have the class module called 'WebSocket'.

    Soon as I changed the Class Module from 'WebSocket' to something else such as 'WebSock' and then change the code in the Main module to:

    Code:
    Sub AppStart (Args() As String)
        srvr.Initialize(
    "srvr")
        srvr.AddWebSocket(
    "/ws""WebSock")
        srvr.Port = 
    51042
        srvr.Start
        StartMessageLoop
    End Sub
    Everything worked as it should. Something so simple to fix but always the last thing to check.

    Thanks for everyone's help.
     
    Daestrum likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice