Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8918849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:51:15+00:00 2026-06-15T05:51:15+00:00

I am trying to create a client signalr app. At present, I am able

  • 0

I am trying to create a client signalr app. At present, I am able to get my MVC clients to send messages to and from the Hub, however, I’m facing some difficulties with my .NET client app

Server Hub code:

namespace ServerHub
{
    public class ChatterBox : Hub
    {

        public void Send(string message)
        {
            Clients.All.addMessage(message);
        }
    }
}

Console App code (almost directly lifted from github)

using Microsoft.AspNet.SignalR.Client.Hubs;
using ServerHub;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
          Say("hello from console");
        }
        public static void Say(string message)
        {
            //var connection = new HubConnection("http://localhost/");

            //IHubProxy myHub = connection.CreateHubProxy("ChatterBox");

            var connection = new HubConnection("http://localhost/");
            //Make proxy to hub based on hub name on server
            var myHub = connection.CreateHubProxy("ChatterBox");
            //Start connection
            connection.Start().ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    Console.WriteLine("Failed to start: {0}", task.Exception.GetBaseException());
                }
                else
                {
                    Console.WriteLine("Success! Connected with client connection id {0}", connection.ConnectionId);
                    // Do more stuff here
                }
            });

            connection.Send("Hello").ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    Console.WriteLine("Send failed {0}", task.Exception.GetBaseException());
                }
                else
                {
                    Console.WriteLine("Success");
                }
            });
        }
    }
}

I get the error message below, during connection.Send()

Start must be called before data can be sent.

Where did I go wrong?

EDIT:

2nd attempt:

    var connection = new HubConnection("http://localhost/");
    //Make proxy to hub based on hub name on server
    var myHub = connection.CreateHubProxy("ChatterBox");
    //Start connection
    connection.Start().ContinueWith(task =>
        {
            if (task.IsFaulted)
            {
                Console.WriteLine("Failed to start: {0}", task.Exception.GetBaseException());
            }
            else
            {
                Console.WriteLine("Success! Connected with client connection id {0}",
                                  connection.ConnectionId);

                // Do more stuff here

                connection.Send("Hello");
            }
        });


    myHub.Invoke("Send", "lol");

Still gives me an error

EDIT: 3rd Attempt

            var connection = new HubConnection("http://localhost:60610/");
            //Make proxy to hub based on hub name on server
            var myHub = connection.CreateHubProxy("ChatterBox");
            //Start connection
            connection.Start().ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    Console.WriteLine("Failed to start: {0}", task.Exception.GetBaseException());
                }
                else
                {
                    //Console.WriteLine("Success! Connected with client connection id {0}", connection.ConnectionId);

                    myHub.Invoke("Send", "lol");
                }
            });

Seems to be working

I also needed to set the port number – e.g., if I’m browsing my MVC website like this: http://localhost:60610/, this is the address I need to set in my console app.

Can I say that during deployment, it won’t be an issue because it’ll be port 80 by default?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:51:16+00:00Added an answer on June 15, 2026 at 5:51 am

    Read this http://msdn.microsoft.com/en-us/library/dd460717.aspx

    TL;DR Start is async and that’s not how you write sequential asynchronous code:

        var connection = new HubConnection("http://localhost/");
        //Make proxy to hub based on hub name on server
        var myHub = connection.CreateHubProxy("ChatterBox");
        //Start connection
        connection.Start().ContinueWith(task =>
        {
            if (task.IsFaulted)
            {
                Console.WriteLine("Failed to start: {0}", task.Exception.GetBaseException());
            }
            else
            {
                Console.WriteLine("Success! Connected with client connection id {0}", connection.ConnectionId);
    
                // Do more stuff here
    
                connection.Send("Hello").ContinueWith(task =>
                {
                     .......
                });
            }
        });
    

    If you can use .NET 4.5 it’ll make your life alot easier:

    var connection = new HubConnection("http://localhost/");
    //Make proxy to hub based on hub name on server
    var myHub = connection.CreateHubProxy("ChatterBox");
    //Start connection
    try 
    {
        await connection.Start();
        Console.WriteLine("Success! Connected with client connection id {0}", connection.ConnectionId);
    }
    catch(Exception ex) 
    {
        Console.WriteLine("Failed to start: {0}", ex.GetBaseException());
    }
    
    await connection.Send("Hello");
    

    UPDATE: Let’s try this again. The code below will work but you should really read that link to learn how to write async code. Otherwise you’ll just run into these problems over and over.

    var connection = new HubConnection("http://localhost/");
    //Make proxy to hub based on hub name on server
    var myHub = connection.CreateHubProxy("ChatterBox");
    //Start connection
    connection.Start().ContinueWith(task =>
        {
            if (task.IsFaulted)
            {
                Console.WriteLine("Failed to start: {0}", task.Exception.GetBaseException());
            }
            else
            {
                Console.WriteLine("Success! Connected with client connection id {0}",
                                  connection.ConnectionId);
    
                myHub.Invoke("Send", "lol");
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a WCF client to send XML messages to a CGI
am trying to create WCF client to consume the service, which contains messages. So
In my MVC4 app, I'm trying to create a client side validator for some
I am trying to create an external python client to access a django app.
I'm trying to create a client-server program that send and receive a string (its
I am trying to create a client library to access Mantis from java. The
I'm trying to create client of 3rd party WS. My app is running on
I'm new to SignalR and am trying send push notifications to a Silverlight client.
Hi i'm trying to create a sever/client program that takes up to 5 clients
I'm trying to create a DHCP Client using Java. The client will send Discover,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.