Send server message to connected clients with Signalr/PersistentConnection

I´m using SignalR/PersistentConnection, not the Hub.

I want to send a message from the server to client. I have the client id to send it, but how can I send a message from server to the client?

Like, when some event happens on server, we want send a notification to a particular user.

Any ideas?


The github page shows how to do this using PersistentConnections.

public class MyConnection : PersistentConnection {
protected override Task OnReceivedAsync(string clientId, string data) {
// Broadcast data to all clients
return Connection.Broadcast(data);


using System;
using System.Web.Routing;
using SignalR.Routing;

public class Global : System.Web.HttpApplication {
protected void Application_Start(object sender, EventArgs e) {
// Register the route for chat
RouteTable.Routes.MapConnection<MyConnection>("echo", "echo/{*operation}");

Then on the client:

$(function () {
var connection = $.connection('echo');

connection.received(function (data) {
$('#messages').append('<li>' + data + '</li>');


$("#broadcast").click(function () {

May be the AddToGroup function in the helps in Server side

Put the clients in to different channels

public bool Join(string channel)
return true;

Then they Can send out message in different channel

public void Send(string channel, string message)

String id = this.Context.ClientId;



using SignalR;
using SignalR.Hosting.AspNet;
using SignalR.Infrastructure;

public class MyConnection : PersistentConnection

public class Notifier
public void Notify(string clientId, object data) {
MyConnection connection = (MyConnection) AspNetHost.DependencyResolver

connection.Send(clientId, data);

Category:signalr Time:2011-09-30 Views:1
Tags: signalr

Related post

  • WCF duplex callbacks, how do I send a message to all clients? 2011-12-19

    I am using WCF with duplex netTcpBinding and I want to send a message to all users connected currently to my service. I thought I could just create a callback contract and it would send a message to all the clients but it seems I am mistaken, and the

  • Is it possible to create a persistent TCP/IP socket connection from a ASP.NET web application/server to a connected client computer? 2012-01-13

    As the title says: Is it possible to create a persistent TCP/IP socket connection from a ASP.NET web application/server to a connected client computer? I know it is a general question, however if it is possible, where would you recommend i start read

  • Simple way of sending a message to a client connected over a network? 2011-12-26

    Possible Duplicate: Transfer files between 2 iPhones over wifi? I already have my device connected to another device over wifi, now what i need to do is to be able to send data between them. I followed a tutorial here:

  • Is there a way that server know the connecting client's hostname? 2011-07-31

    Client is given a server's hostname, so that client can connect to the server with the given hostname. //client side host = new InetSocketAddress ( args[0], 50000); // args[0] = server's address sockfd = new Socket(host.getHostName(),host.getPort());

  • Sending a message to a client via its 2011-12-11

    I can only seem emit messages to users when their socket id has been directly stored within the io.sockets.on('connect') function. I don't know why it doesn't work when trying to store their socket id after they have logged in. Working: var clients =

  • Send command to all connected clients 2012-04-12

    I have a TIdHttpServer i must keep the connection open in order to send some commands back to the clients. I want to iterate when i press a button and send a command to all connected clients. How can i do this ? --------------Solutions------------- Y

  • Send a message to all clients in a Group, except for the current client 2012-04-13

    I want to execute a method on all connected clients from the server, except for the current client. Any way to do this without me maintaining my own list of clientids? TIA! --------------Solutions------------- This functionality has been proposed and

  • SVN post-commit hook sending a message back to client 2011-12-08

    I'm writing a post-commit script in bash, and I'd like to pass messages back to the client who's making a commit. However echo my message >&2 isn't making it back to the client. Is it even possible to send messages back with a post-commit hook

  • Can't send a message: not connected to the host (was: Network Programs Network Networking Internet Website Web Site URL Web Site) 2013-12-04

    When we attempt to send messages, amessage appears that we arenot connected to the host. We can receive emails. Can you suggest a solution? --------------Solutions------------- Hi KennethRowles, Thank you for contacting Microsoft Community forum. Let

  • Sending server messages with google - account suspended 2012-03-07

    While manually testing our app we found that the server does not send emails anymore (using SMTP). It was because Google has suspended our account: "This user has been suspended for abuse." What are the limitation on sending emails and how can we ove

  • How to get a server to send a client a message on connection? 2011-03-10

    I am trying to write a basic client-server program to allow the client to traverse the files of the server. I wish to get the server to, on connection of the client, send a list of all the files in the current directory to the client. How would I go

  • If my server knows a remote client's IP address, how do I send a message to the remote client? 2009-09-28

    The remote client is a desktop application running a windows.forms application. How do I have the server send the client a message, knowing the client's IP address? --------------Solutions------------- Check out these tutorials: Simple Threaded TCP S

  • When client sends a message to server, the message gets truncated 2011-07-25

    I'm new to multithreading. Im trying to do sending of messages between a client and a server. When I send a message to the server, my output in the server is supposed to be "Aji Computer: Thanks! :D", but instead I get a truncated data "Aji Computer:

  • SignalR - Sending a Message to a subset of users 2012-04-03

    I need to send updates via SignalR to a users "Friends", not all connected users. Clients.callbackName() Sends a message to All Connected Clients. How do I send a message to just a few clients? --------------Solutions------------- You can specify the

  • SignalR - Sending a Message from a WCF Project 2012-04-04

    I've followed the instructions from entitled "Broadcasting over a Hub from outside of a Hub". I got this method working from within an MVC Action in the same project. Requesting the Action sends the update

  • How to send data to a particular Client from server? 2010-08-20

    I have programmed a chat application in VB but as soon as I send any data from a client the server will send it to all. It should send a reply only to a particular client. This is the function I have used. Dim objClient As Client Dim d As DictionaryE

  • How to properly send an HTTP message to the client 2009-07-08

    I'm working on a RESTful web service in Java. I need a good way to send error messages to the client if something's wrong. According to the Javadoc, HttpServletResponse.setStatus(int status, String message) is deprecated "due to ambiguous meaning of

  • simple TCP client serve model in C : client not recieving 2011-09-09

    im making a simple TCP client-server in c and im trying to send a message from the client to the server, but im having some problems with it. The server does send the message (integer value > 0) but the client is unable to receive it (integer valu

  • Java RMI RemoteException after sending last message 2011-11-17

    So I've made a client/server pair in Java using RMI. The point is to send messages from the client to the server and print out how many messages we've received and how many we've lost (im comparing it to UDP so dont ask why I'm expecting to lose any

Copyright (C), All Rights Reserved.

processed in 0.266 (s). 13 q(s)