albusorin
March 6th, 2006, 01:27 AM
Hello,
This code makes a TCP server in RemoteServer. When it gets data on port 333 it instantiate HelloRemoteServer. The question is:
how can I know the instance of RemoteServer in class HelloRemoteServer and call MyFunction()?
namespace RemoteTestServer
{
public interface iInterface
{
string HelloMethod(string name);
}
class RemoteServerTest
{
[STAThread]
static void Main(string[] args)
{
RemoteServer rs = new RemoteServer();
}
}
class RemoteServer
{
public RemoteServer
{
TcpChannel chan = new TcpChannel(333);
ChannelServices.RegisterChannel(chan);
RemotingConfiguration.RegisterWellKnownServiceType(
Type.GetType("RemoteTestServer.HelloRemoteServer"),
"Hello", WellKnownObjectMode.SingleCall);
System.Console.WriteLine("Hit to exit...");
System.Console.ReadLine();
}
public void MyFunction()
{
//how ca I call this from HelloRemoteServer
}
}
class HelloRemoteServer : MarshalByRefObject, iInterface
{
public HelloRemoteServer()
{
Console.WriteLine("HelloServer activated");
}
public string HelloMethod(string name)
{
Console.WriteLine("Hello.HelloMethod : {0}", name);
return "Hi there " + name;
}
}
}
Thanks in advanced!
Ps: the remote of tcp:
TcpChannel chan = new TcpChannel();
ChannelServices.RegisterChannel(chan);
iInterface obj = (iInterface)Activator.GetObject(
typeof(RemoteTestServer.iInterface),
"tcp://localhost:333/Hello");
if (obj != null)
{
obj.SayHellow("it's me");
}
This code makes a TCP server in RemoteServer. When it gets data on port 333 it instantiate HelloRemoteServer. The question is:
how can I know the instance of RemoteServer in class HelloRemoteServer and call MyFunction()?
namespace RemoteTestServer
{
public interface iInterface
{
string HelloMethod(string name);
}
class RemoteServerTest
{
[STAThread]
static void Main(string[] args)
{
RemoteServer rs = new RemoteServer();
}
}
class RemoteServer
{
public RemoteServer
{
TcpChannel chan = new TcpChannel(333);
ChannelServices.RegisterChannel(chan);
RemotingConfiguration.RegisterWellKnownServiceType(
Type.GetType("RemoteTestServer.HelloRemoteServer"),
"Hello", WellKnownObjectMode.SingleCall);
System.Console.WriteLine("Hit to exit...");
System.Console.ReadLine();
}
public void MyFunction()
{
//how ca I call this from HelloRemoteServer
}
}
class HelloRemoteServer : MarshalByRefObject, iInterface
{
public HelloRemoteServer()
{
Console.WriteLine("HelloServer activated");
}
public string HelloMethod(string name)
{
Console.WriteLine("Hello.HelloMethod : {0}", name);
return "Hi there " + name;
}
}
}
Thanks in advanced!
Ps: the remote of tcp:
TcpChannel chan = new TcpChannel();
ChannelServices.RegisterChannel(chan);
iInterface obj = (iInterface)Activator.GetObject(
typeof(RemoteTestServer.iInterface),
"tcp://localhost:333/Hello");
if (obj != null)
{
obj.SayHellow("it's me");
}