Sunny
7/31/2004 11:08:00 PM
Hi Jason,
I can not reproduce the problem. Here it takes less than a second. But
it may depend on the DNS resolution. Have you tried to pass an IP
instead of server name to the client?
I have added the current time in the output, so I can what happens. Of
course, you have to be sure that the clocks of both machines are in
sync.
Here is the code I tries:
using System;
using System.Windows.Forms;
namespace Samples {
public class MyRemoteObject: System.MarshalByRefObject {
public MyRemoteObject() {
Console.WriteLine("{0} - MyRemoteObject Constructor Called",
DateTime.Now);
}
public String ComputerName() {
Console.WriteLine("{0} - ComputerName Called", DateTime.Now);
return SystemInformation.ComputerName;
}
}
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using Samples;
namespace Samples {
class SimpleServer {
static void Main(string [] args) {
ChannelServices.RegisterChannel(new TcpChannel(8085));
RemotingConfiguration.RegisterActivatedServiceType(typeof
(MyRemoteObject));
Console.WriteLine("Press return to exit");
Console.ReadLine();
}
}
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Activation;
using Samples;
namespace Samples {
class SimpleClient {
static void Main(string[] args) {
if (args.Length == 0) {
Console.WriteLine("usage: simpleclient HostServerName");
return;
}
Console.WriteLine("{0} - Started", DateTime.Now);
object[] url = { new UrlAttribute("tcp://" + args[0] + ":8085") };
MyRemoteObject robj = (MyRemoteObject) Activator.CreateInstance
(typeof(MyRemoteObject), null, url);
Console.WriteLine("{0} - Remote call: {1}", DateTime.Now,
robj.ComputerName());
Console.WriteLine("{0} - Remote call: {1}", DateTime.Now,
robj.ComputerName());
}
}
}
My output on the client is:
C:\temp\cs_test>simpleclient test1
7/31/2004 5:57:32 PM - Started
7/31/2004 5:57:33 PM - Remote call: TEST1
7/31/2004 5:57:33 PM - Remote call: TEST1
and from the server:
C:\temp>simpleserver
Press return to exit
7/31/2004 5:57:33 PM - MyRemoteObject Constructor Called
7/31/2004 5:57:33 PM - ComputerName Called
7/31/2004 5:57:33 PM - ComputerName Called
Sunny
In article <O8uoqQZdEHA.3476@tk2msftngp13.phx.gbl>, abc@xyz.com says...
> I am having an issue w/ the performace of a CAO. The first method call seems
> to take between 7 and 30 seconds to respond when the server and client are
> on different machines. If they are on the same machine, the performance is
> fine. It seems to me like the response should not take this long. Am I
> correct, or is this the type of performance I should expect w/ CAO's?
>
> I have included the source to four files that demonstrate this problem
> (MyRemoteObject.cs, SimpleServer.cs, SimpleClient.cs and make.bat). Any help
> or information would be greatly appreciated.
>
> TIA,
> Jason
>
> MyRemoteObject.cs:
> using System;
> using System.Windows.Forms;
>
> namespace Samples {
> public class MyRemoteObject: System.MarshalByRefObject {
>
> public MyRemoteObject() {
> Console.WriteLine("MyRemoteObject Constructor Called");
> }
>
> public String ComputerName() {
> Console.WriteLine("ComputerName Called");
> return SystemInformation.ComputerName;
> }
> }
> }
>
>
> SimpleServer.cs:
> using System;
> using System.Runtime.Remoting;
> using System.Runtime.Remoting.Channels;
> using System.Runtime.Remoting.Channels.Tcp;
> using Samples;
>
> namespace Samples {
> class SimpleServer {
> static void Main(string [] args) {
> ChannelServices.RegisterChannel(new TcpChannel(8085));
>
> RemotingConfiguration.RegisterActivatedServiceType(typeof(MyRemoteObject));
>
> Console.WriteLine("Press return to exit");
> Console.ReadLine();
> }
> }
> }
>
>
> SimpleClient.cs:
> using System;
> using System.Runtime.Remoting;
> using System.Runtime.Remoting.Channels;
> using System.Runtime.Remoting.Channels.Tcp;
> using System.Runtime.Remoting.Activation;
> using Samples;
>
> namespace Samples {
> class SimpleClient {
> static void Main(string[] args) {
> if (args.Length == 0) {
> Console.WriteLine("usage: simpleclient HostServerName");
> return;
> }
>
> object[] url = { new UrlAttribute("tcp://" + args[0] + ":8085") };
>
> MyRemoteObject robj = (MyRemoteObject)
> Activator.CreateInstance(typeof(MyRemoteObject), null, url);
> Console.WriteLine(robj.ComputerName());
> Console.WriteLine(robj.ComputerName());
> }
> }
> }
>
>
> make.bat:
> csc /t:library /out:MyRemoteObjects.dll MyRemoteObject.cs MyRemoteObject2.cs
> csc /t:exe /r:MyRemoteObjects.dll SimpleServer.cs
> csc /t:exe /r:MyRemoteObjects.dll SimpleClient.cs
>
>
>