Pregunta

Esta es mi aplicación Hello World Remoting.

using System;
using System.Collections.Generic;
using System.Text;

namespace Remoting__HelloWorld.UI.Client
{
    public interface MyInterface
    {
        int FunctionOne(string str);
    }
}

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace Remoting__HelloWorld.UI.Client
{
    class MyClient
    {
        public static void Main()
        {
            TcpChannel tcpChannel = new TcpChannel();

            ChannelServices.RegisterChannel(tcpChannel);

            MyInterface remoteObj = (MyInterface) 
            Activator.GetObject(typeof(MyInterface), "tcp://localhost:8080/FirstRemote");

            Console.WriteLine(remoteObj.FunctionOne("Hello World!"));
        }
    }
}


using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using Remoting__HelloWorld.UI.Client;

namespace Remoting__HelloWorld.UI.Server
{
    public class MyRemoteClass : MarshalByRefObject, MyInterface
    {
        public int FunctionOne(string str)
        {
            return str.Length;
        }
    }
}


using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace Remoting__HelloWorld.UI.Server
{
    class Program
    {
        static void Main(string[] args)
        {
            TcpChannel tcpChannel = new TcpChannel(9999);

            ChannelServices.RegisterChannel(tcpChannel);

            RemotingConfiguration.RegisterWellKnownServiceType(typeof(MyRemoteClass), "FirstRemote", WellKnownObjectMode.SingleCall);

            System.Console.WriteLine("Press ENTER to quit");
            System.Console.ReadLine();
        }
    }
}

Pero después de ejecutar esta aplicación, obtengo la siguiente excepción:

No connection could be made because the target machine 
actively refused it 127.0.0.1:8080

¿Cómo puedo solucionar esto?

¿Fue útil?

Solución

O cambia el servidor de esta manera:

TcpChannel tcpChannel = new TcpChannel(8080);

o cambia el cliente de esta manera:

Activator.GetObject(typeof(MyInterface), "tcp://localhost:9999/FirstRemote");

En el lado del servidor, está abriendo un canal en el número de puerto especificado (en su ejemplo, está usando el puerto 9999). En esencia, esto le dice al servidor que "escuche" las solicitudes entrantes en el puerto 9999. En el lado del cliente, le dice a qué número de puerto debe conectarse (en su ejemplo, está usando el puerto 8080). Entonces, tiene una situación en la que su servidor está escuchando en el puerto 9999, pero su cliente está intentando conectarse en el puerto 8080. Estos números de puerto deben coincidir.

Otros consejos

el servidor tcpChannel es 9999 las solicitudes del cliente hacia 8080

Su servidor está abriendo el canal en el puerto 9999 mientras el cliente está buscando 8080.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top