.Net Remoting uses only one connection?

Does .Net Remoting open multiple connections or only one? let's say I have a server and a client. if the client creates multiple SingleCall objects. will there be a new connection for each object or will there be one connection for each object?

I can not find the answer anywhere.

+5
source share
2 answers

The number of network connections depends on the forwarding channel used. By default, TcpChannel opens as many network connections as there are threads in your program trying to access the server for one point.

For single-threaded applications, TcpChannel uses a single network connection.

IiopChannel , , .

0

: . - . .

. 2 1 , . , - .

-, :

public interface IFactory {

    string Hello(string name);

}

. :

private static TcpChannel channel;

static void Main(string[] args) {

  BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
  BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
  serverProv.TypeFilterLevel = TypeFilterLevel.Full;

  channel = new TcpChannel(
    properties: new Hashtable {
      { @"port", 2013 }
    },
    clientSinkProvider: clientProv,
    serverSinkProvider: serverProv
  );
  ChannelServices.RegisterChannel(channel, false);
  RemotingConfiguration.RegisterWellKnownServiceType(typeof(Factory), "Factory.rem", WellKnownObjectMode.SingleCall);

  Console.WriteLine("Server started...");
  Console.WriteLine("Press any key to stop...");
  Console.ReadKey(intercept: true);

}

Factory.

RemotingConfiguration.RegisterWellKnownServiceType(typeof(Factory), "Factory.rem", WellKnownObjectMode.SingleCall);

. IFactory:

private sealed class Factory : MarshalByRefObject, IFactory {

  #region IFactory Members

  string IFactory.Hello(string name) {
    return @"Hello " + name + @" !";
  }

  #endregion

}

:

static void Main(string[] args) {

  Console.WriteLine("Press any key to connect...");
  Console.ReadKey(intercept: true);

  IFactory factory = Activator.GetObject(typeof(IFactory), @"tcp://127.0.0.1:2013/Factory.rem") as IFactory;

  EventWaitHandle signal = new EventWaitHandle(initialState: false, mode: EventResetMode.ManualReset);

  ThreadStart action = () => {

    signal.WaitOne();
    var result = factory.Hello("Eduard");
    Console.WriteLine(result);

  };

  foreach (var i in Enumerable.Range(0, 99))
    new Thread(action) { IsBackground = true }.Start();

  Console.WriteLine("Press any key to bombard server...");
  Console.ReadKey(intercept: true);

  signal.Set();


  Console.ReadKey(intercept: true);
}

, . - SingleCall ( , TCP- 2013):

IFactory factory = Activator.GetObject(typeof(IFactory), @"tcp://127.0.0.1:2013/Factory.rem") as IFactory;

"simulataneous-ness" 100 , ( ), " " ( ), " ":

EventWaitHandle signal = new EventWaitHandle(initialState: false, mode: EventResetMode.ManualReset);

ThreadStart action = () => {

  signal.WaitOne();
  var result = factory.Hello("Eduard");
  Console.WriteLine(result);

};

foreach (var i in Enumerable.Range(0, 99))
  new Thread(action) { IsBackground = true }.Start();

, 100 , :

signal.WaitOne();

, , .

, " " 100 Hello invocations:

Console.WriteLine("Press any key to bombard server...");
Console.ReadKey(intercept: true);

signal.Set();

:

1) :

enter image description here

2) , " ", ( , ), "",

enter image description here

3) Mark Russinovich Process Explorer , TCP/IP:

enter image description here

4) TA DAA!! Process Explorer. ? , . , . ( 5 10 ) , ( .NET Remoting).

enter image description here

, , , .

, .NET Remoting ( , TcpChannel, Microsoft, , .NET Remoting, , IIS ..).

+7

All Articles