PDA

View Full Version : Remoting - Error.


shawnj
11-10-2008, 04:19 PM
I'm attempting to implement .net's remoting in an indicator and I'm stuck at the very beginning.

I've added the reference:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Syst em.Runtime.Remoting.dll


And my code:

using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

protected override void Initialize()
{
try
{
TcpChannel c = new TcpChannel(32469);
}
catch(Exception ex)
{
Print(ex.Message);
}
}

When I open the Indicators Dialog, I get the following Error message printed in the Output window:
"Only one usage of each socket address (protocol/network address/port) is normally permitted"

I've tried a bunch of different port numbers so I'm pretty sure that is not the problem.

Creating and registering (not show here) a channel is basically the first step in implementing a remoting server. I'm guessing this is clashing with something in NinjaTrader.

Has anyone been able to get remoting working in an indicator? Any thoughts on how to proceed to troubleshoot/workaround this error?

I'm trying to use remoting to workaround the NT6.5 limitation of not being able to utilize multiple data series from an indicator.

thanks,
shawnj

mrlogik
11-10-2008, 07:24 PM
Just to be safe, I would move the code to the OnBarUpdate() function and use an init variable

if(!init)
{
init = true;
//the rest of the code
}

I think sometimes the Initialize code is called multiple times prior to putting the indicator on the chart.

shawnj
11-11-2008, 06:51 AM
Thanks mrlogik, I've implemented your logic and with some further trial and error I think I've concluded the following: When the Indicator is first applied and executed, the error does not occur, however, if I remove the Indicator and reapply it then reexecute it, the error returns. The only way I can get back to a clean execution is to exit NT and start over.

This indicates to me that removing the Indicator is not releasing the TcpChannel object.

So my next thought was to override the Indicator's Dispose to try to force the release of the TcpChannel object.

public override void Dispose()
{
FTcpChannel.Dispose();
base.Dispose();
}

Unfortunately the best I can tell, TcpChannel does not inplement Dispose() and I cant call Finalize(). This is getting into an area of C# that I'm pretty weak at.

This attempt at implementing Remoting in a NT Indicator is "Eating my lunch <g>".

mrlogik
11-11-2008, 06:59 AM
shawn,

I think what you have should work. You don't see a Dispose() method for FTcpChannel?

Either way, before you do it check to see if its null


if(FTcpChannel != null)
{
//dispose the FTcpChannel
}


some (http://www.experts-exchange.com/Microsoft/Development/.NET/Q_23695159.html) reading