javascript - SignalR client not firing server code -


i testing signal basic string. client side not firing server code , there no error. added [hubname("myhub1")] , [hubmethodname("getvaluestring")] in because if not javascript complaint client undefine , methodname not found.

after added 2 meta in. there no error server code not fire. please.

client script

(function () {     // defining connection server hub.     debugger     var myhub = $.connection.myhub1;     // setting logging true can see whats happening in browser console log. [optional]     $.connection.hub.logging = true;     // start hub     $.connection.hub.start();      // client method being called inside myhub constructor method every 3 seconds     myhub.client.getvaluestring = function (servertime) {         // set received servertime in span show in browser         $("#newtime").html(servertime);     }; }()); 

server script

[hubname("myhub1")] public class myhub1 : hub {     public void hello()     {         clients.all.hello();     }     [hubmethodname("getvaluestring")]     public void getstring() {         var tasktimer = task.factory.startnew(async () =>         {             while (true)             {                 string timenow = datetime.now.tostring();                 //sending server time connected clients on client method ()                 clients.all.getvaluestring("test");                 //delaying 3 seconds.                 await task.delay(3000);             }         }, taskcreationoptions.longrunning           );       } } 

update 1 change javascript , output "undefine" no error

var haha = myhub.client.getvaluestring; // set received servertime in span show in browser enter image description here

try give ago. also, use this reference

i've added console.log try , see if see when run code.

(function () {      var myhub = $.connection.myhub1;      myhub.client.getvaluestring = function (servertime) {          $("#newtime").html(servertime);     };      $.connection.hub.logging = true;      $.connection.hub.start().done(function() {         console.log("hub ready"); // tell me if see message in console log         myhub.server.getstring() // note wrote getstring small g, has be.     });   }());  [hubname("myhub1")] public class myhub1 : hub {     public void hello()     {         clients.all.hello();     }      public void getstring() {         var tasktimer = task.factory.startnew(async () =>         {             while (true)             {                 string timenow = datetime.now.tostring();                 //sending server time connected clients on client method ()                 clients.all.getvaluestring("test");                 //delaying 3 seconds.                 await task.delay(3000);             }         }, taskcreationoptions.longrunning           );       } } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -