문제

이것은 내 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();
        }
    }
}

그러나이 앱을 실행 한 후에는 다음과 같은 예외를 얻고 있습니다.

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

이것을 어떻게 고칠 수 있습니까?

도움이 되었습니까?

해결책

다음과 같이 서버를 변경하십시오.

TcpChannel tcpChannel = new TcpChannel(8080);

또는 다음과 같이 클라이언트를 변경하십시오.

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

서버 측에서 지정된 포트 번호에 채널을 열고 있습니다 (예에서는 포트 9999를 사용하고 있음). 본질적으로, 이것은 서버에게 포트 9999의 들어오는 요청에 대해 '듣기'하도록 지시합니다. 클라이언트 측에서, 당신은 어떤 포트 번호에 연결할 포트 번호를 알려줍니다 (예에서는 포트 8080을 사용하고 있습니다). 따라서 서버가 포트 9999에서 듣는 상황이 있지만 클라이언트는 포트 8080에서 연결하려고합니다.이 포트 번호는 일치해야합니다.

다른 팁

서버 tcpChannel은 9999입니다. 클라이언트는 8080을 향해 요청합니다.

클라이언트가 8080을 찾고있는 동안 서버가 포트 9999에서 채널을 열고 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top