0

I'm developing a Windows 8.1 chat client app with metro app and win32 desktop. Problem in not connected from winrt app to win32 app on Tcp socket - exception connected failed with error not reply from other computer. What's the problem?

I'm testing on the locale mashine:

void Connector::ConnectSocketTsp(void)
{
    socket = ref new StreamSocket();

    rootPage->NotifyUser("Connecting to ...", NotifyType::StatusMessage);

    {
        HostName^ serverHost = ref new HostName("127.0.0.1");   //("localhost");
        // Connect...
        create_task(socket->ConnectAsync(
            serverHost, "15500", SocketProtectionLevel::PlainSocket)).then([this](task<void> previousTask)
        {
            try
            {
                previousTask.get();
                rootPage->NotifyUser("Connected", NotifyType::StatusMessage);

                m_reader = ref new DataReader(socket->InputStream);
                m_reader->InputStreamOptions = InputStreamOptions::ReadAhead;
                m_writer = ref new DataWriter(socket->OutputStream);

                ReceiveStringLoop(m_reader, socket);

            }
            catch (Exception^ exception)
            {
                rootPage->NotifyUser("Connect failed with error: " + exception->Message, NotifyType::ErrorMessage);
            }
        });
    }
}

exception->Message = "An attempt to connect was unsuccessful because from another computer in the required time you get the desired response has been disconnected or established connection due to an incorrect response is already connected computer."

And service to translate messages:

void start()
{
    logMessage(QString("Start service"), QtServiceBase::Information);

    QCoreApplication *app = application();

    daemon = new ClientSocket(15500, app);

    if ( !daemon->listen(QHostAddress::LocalHost, 15500) )      // QHostAddress::Any
        logMessage(QString("Failed to bind to port %1").arg(daemon->serverPort()), QtServiceBase::Error);       
    else
        logMessage(QString("Success to bind to port %1").arg(daemon->serverPort()), QtServiceBase::Information);

    if ( !daemon->isListening() )
    {
        logMessage(QString("Failed to bind to port %1").arg(daemon->serverPort()), QtServiceBase::Error);
        app->quit();
    }   
}

Telnet successfully connects to 127.0.0.1 15500...

  • 1
    Please add some of the code that you're seeing this connection exception. Also, please do a telnet on the port that you're trying to connect on to verify that the socket that you're trying to reach is actually open. It could be that the service on the other computer is down. – Jason D Oct 23 '14 at 15:32
  • May be firewall blocks? – Eugene Andreev Oct 24 '14 at 15:27
  • I would vote to close as a duplicate of one of the following, but I already voted to close for a different reason. See these possible dups: 1. [How can a Metro app in Windows 8 communicate with a backend desktop app on the same machine?](http://stackoverflow.com/questions/7465517/how-can-a-metro-app-in-windows-8-communicate-with-a-backend-desktop-app-on-the-s), and 2. [Can't use StreamSocket to connect to a TcpListener](http://stackoverflow.com/questions/13410186/cant-use-streamsocket-to-connect-to-a-tcplistener) – chue x Oct 25 '14 at 15:02
  • I should add that your problem is that Windows Store apps are restricted from connecting to localhost. Both links above say "it can't be done", but the first provides some unsupported workarounds. – chue x Oct 25 '14 at 15:07

1 Answers1

3

Windows Store apps by default are blocked from connecting to other apps on the same machine.

This block can be suppressed during debugging or (as of the Windows 8.1 Update) bypassed for side-loaded apps (chue x's links and "can't be done" comment are true for Windows 8, but now out of date).

There is no certifiable way to loop back for an app deployed through the store.

See How to enable loopback and troubleshoot network isolation (Windows Store apps) and Using network loopback in side-loaded Windows Store apps

Rob Caplan - MSFT
  • 21,144
  • 3
  • 30
  • 51
  • Interesting piece of info! I somehow missed the restriction bypass for side-loaded apps when reading MSDN's [Windows 8.1: New APIs and Features](http://msdn.microsoft.com/en-us/library/windows/apps/dn751496.aspx). – chue x Oct 26 '14 at 16:24