c# - Sending Messages from the Server to the Client with SignalR -


i have been reading article documentation:

http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/tutorial-getting-started-with-signalr-20-and-mvc-5

it says, can send message client server so:

$.connection.hub.start().done(function () {     $('#sendmessage').click(function () {         // call send method on hub.          chat.server.send($('#displayname').val(), $('#message').val());         // clear text box , reset focus next comment.          $('#message').val('').focus();     }); }); 

but, how can send message server client?

i first following tutorial http://www.codemag.com/article/1210071 explained need this:

sendmessage("index action invoked."); 

with sendmessage() defined as:

private void sendmessage(string message) {     globalhost.connectionmanager.gethubcontext<notificationhub>().clients.all.sendmessage(message); } 

but, doesn't work. on client side, error is:

object # has no method 'activate'

the client side code using is:

$.connection.hub.start(function () {     notificationhub.activate(function (response) {         /*         $("#target")          .find('ul')          .append($("<li></li>").html(response));          */         console.log(response);     }); }); 

so, question is, how can send simple message server client?

can show me complete example of how this? have seen stock ticker example documentation, kind of hard understand/ apply.

from understand calling function on client called sendmessage here

private void sendmessage(string message) {     globalhost.connectionmanager.gethubcontext<notificationhub>().clients.all.sendmessage(message); } 

however, don't see definition function on client side. instead have defined function called activate(). additionally, working code, have defined client side functions this.

    var hub = $.connection.notificationhub;     hub.client.sendmessage= function (data) { //some logic here } 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -