0
votes

Trying to create a Console application that is going to send data to a website. The website is built with Codeiginter framework, if that matters.

When i'm running my Console application, i get the error that a connection could not be made, and that the machine refused it.

Been watching some tutorials, but most of them are using Hubs etc, which imo i do not need for this simple task?. All i want to do is to send data to the website, one way.

Here is my Console application

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Client;

namespace signalrDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            var connection = new Connection("http://localhost:3000/servers/2");

            connection.Received += data => Console.WriteLine(data);

            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);

                }
            });

            Console.ReadLine();
        }

    }
}

And at my website, i have this code

    $(function () {


        var connection = $.connection('http://localhost/servers/2');

        connection.received(function (data) {

            $("message").append(data + '<br />');

        });


         connection.start().done();



    });

Thank you.

1
So do you have a server listening on localhost:3000? You javascript client tries to connect to port 80 - again do you have anything listening on this port? Because the exception basically says that the port you are trying to connect to is closed and therefore the connection cannot be made. - Pawel
Well, all i have is the console application and the website with the javascript, as mentioned above. So i do need a server too? - Dexception
If you sent a request somewhere there must be something that is goint to handle the request. I would recommend that you go through SignalR tutorials. Here is one that shows how to use SignalR with javascript client: asp.net/signalr/overview/signalr-20/…. - Pawel
Alright, thank you. I'll do that! - Dexception

1 Answers

0
votes

Your best bet is to use hubs. You need a location or service for the client to connect to which in signalr is a hub.