Remoting TcpChannel Timeout ? ?

S

Sagaert Johan

Hi

When the remoting server starts and the client immediate begins calling the
remote object on the server no problems.
But when the client does not need to access the remote object for some time
the connection seems to be broken on the next attempt to do a call to the
remote object on the server. (i need to restart the server application to
get it working again ).

So it appears if the remoting connection is idle for some time ( about a
minute max ) the connection seems to break.
When there are regular call it ran for a whole day without problems.



Any way i can fix this ?

Thanks ,
Johan


this is how i ini the remote server
// Register our tcp channel

ChannelServices.RegisterChannel(new TcpChannel(setting.RemotePort), false);

// Register an object created by the server

rmDisplay = new Display(); //inherits from MarshalByRefObject


ObjRef refDisplay = RemotingServices.Marshal(rmDisplay, "Display");
 
G

Guest

Can you pls tell me is it Client Activated or Server Activated object? The
life time of Marshal by reference remote object is maintained by the Lease,
Lease Manager and several Sponsors. Lease defines the life time of the remote
object. You can either give long time duration for the remote object in
InitializeLifeTimeService or you can implement ISponsor Interface in calling
application and then override RenewLease() to solve this problem
 
S

Sagaert Johan

Hi

I included some code snippets for illustration

if i start the server app and wait some time before starting the client then
if fails with an exception on the client program.
(saying i need to turn off customErrors ....? )

If i call the methods on a regular basis then no problems..



/////////////// CODE ON SERVER PART (remote display
/////////////////////////

public partial class Form1 : Form
{
....
private Display rmDisplay;
....


#region init code
public Form1()
{
InitializeComponent();

// Register our tcp channel
ChannelServices.RegisterChannel(new TcpChannel(50050), false);

// Register an object created by the server
rmDisplay = new Display();

ObjRef refDisplay = RemotingServices.Marshal(rmDisplay,
"Display");

rmDisplay.RtfMessagebox = this.rtb_meldingen; // pass the
richtextbox on the form to the Display class
rmDisplay.ControlOwner = this; // needed for Control.Invoke

rmDisplay.SetDisplayTiming += new
Display.SetDisplayTimingHandler(rmDisplay_SetDisplayTiming);
rmDisplay.SetWorkLoadEvent += new
Display.SetWorkLoadHandler(rmDisplay_SetWorkLoadEvent);
rmDisplay.IncomingEvent += new
Display.IncomingEventHandler(rmDisplay_IncomingEvent);


System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
MyFormatter = new
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
MyFormatter.FilterLevel =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
}

// rest of source cut
....
....


}



// snippet from display class

class Display : MarshalByRefObject
{
public RichTextBox RtfMessagebox;
public Control ControlOwner;

public delegate void SetDisplayTimingHandler(object sender, int
displaylogo_timeout,int displayoff_timeout);
public event SetDisplayTimingHandler SetDisplayTiming;

public delegate void SetWorkLoadHandler(object sender, int
workload);
public event SetWorkLoadHandler SetWorkLoadEvent;

public delegate void IncomingEventHandler(object sender);
public event IncomingEventHandler IncomingEvent;



public Display()
{

}

delegate void SetTimesCallback(int displaylogo_timeout, int
displayoff_timeout);

// call its own if Control.Invoke is required to avoid cross thread
problems
public void SetTiming(int displaylogo_timeout,int
displayoff_timeout)
{
if (SetDisplayTiming != null)
{
if (ControlOwner.InvokeRequired == false)
SetDisplayTiming(this, displaylogo_timeout,
displayoff_timeout);
else
{
SetTimesCallback d = new SetTimesCallback(SetTiming);
ControlOwner.Invoke(d, new object[] {
displaylogo_timeout, displayoff_timeout });
}
}
}

//rest of code cut
...
...
}






///////////////////// CODE on CLient app. (app controlling the remote
display)

// this function is used on the remote client to call the method on the
server

private void SetTimeLimits(int t_logo,int t_poweroff)
{
TcpClientChannel displaych2 = new TcpClientChannel();
ChannelServices.RegisterChannel(displaych2, false);

Display rDisplay;

rDisplay = (Display)Activator.GetObject(typeof(Display),
"tcp://192.168.1.3:50050/Display");

rDisplay.SetTiming(t_logo, t_poweroff);

ChannelServices.UnregisterChannel(displaych2);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top