How to add a cron job to my custom server(.net, RO9.2 RODL-based)

Hi, I’m developing a mobile server, it will synchronize data with another RO server.
I create a Remoting SDK Server(RODL-based) by wizard, My question is:

  1. where should I add my code, my server will installed as a windows service. so I don’t think I can add timer to Form;

  2. Same reason, where can I add zeroconfregistration.

  3. By the way, I found Bonjour Discovery can not work in some network, so I built a simple UDP listener, but I don’t know how to add it to RO server

Hello

Mark the service class you want to register in ZeroConf with this attribute:

[RemObjects.SDK.Server.ZeroConfServiceType("ServiceNameHere")]

The enable ZeroConf in Program.cs using

...
server.NetworkServer.EnableZeroConf = true; // This line enables ZeroConf registation
server.Run(args);

You need to provide either your own implementation of Windows Service class or an own implementation of the NetworkServer (a core server component that actually performs the network communications). In general the 2nd approach requires way less code. You need just to add a class like this to your server project:

[RemObjects.SDK.Server.ServerInfrastructure]
public class CustomNetworkServer: RemObjects.SDK.Server.NetworkServer
{
}

Note the attribute applied to this class. It ensures that Remoting SDK will use this class as its NetworkServer implementation. Also because we use the RemObjects.SDK.Server.NetworkServer class as the base here, we already have all the required functionality implemented.

The RemObjects.SDK.Server.NetworkServer class provides a set of methods that can be overridden. You might be interested in the InternalStart and InternalStop methods. Override them to add the functionality you need like starting custom listeners etc (please do NOT forget to call base.InternalStart / base.InternalStop methods).

Also in case you need to use your own ZeroConf implementation you can override methods RegisterZeroConfService and UnregisterZeroConfService, where you can call your own UDP implementation instead of built-in one.

As for the periodic jobs - the NetworkServer instance’s lifecycle matches to the one of the entire application. You can add your timer and callbacks to this class too.

Regards

Thanks, I had add my time service successfully, but I failed to add a ZeroConfRegistration to my server.
I tried as following(Program.cs)

ApplicationServer server = new ApplicationServer(“ROServerTest”);
ZeroConfRegistration zeroConf = new ZeroConfRegistration();
IpSuperTcpServerChannel srvChannel = new IpSuperTcpServerChannel();
srvChannel.Port = 8000;
server.NetworkServer.ServerChannel = srvChannel;
zeroConf.Domain = “local.”;
zeroConf.ServerChannel = server.NetworkServer.ServerChannel;
zeroConf.ServerName = “NetDiscoverableServer”;
server.NetworkServer.EnableZeroConf = true;
server.Run(args);
then add [RemObjects.SDK.Server.ZeroConfServiceType(“Service1”)] to my service class

I can start it without error, but I can’t discover it using zeroconfbrowser.
and I found some error in windows application log:
Bad service type in TT-PC._bonjourdiscoverableservice_rosdk._tcp.local. Application protocal name must be underscore plus 1-15 characters

Hello

At first, please remove either

ZeroConfRegistration zeroConf = new ZeroConfRegistration();
zeroConf.Domain = “local.”;
zeroConf.ServerChannel = server.NetworkServer.ServerChannel;
zeroConf.ServerName = “NetDiscoverableServer”;

or

server.NetworkServer.EnableZeroConf = true;

because you essentially create registering component twice.

How exactly do you try to discover it? Note that even with this twice registered server both a ZeroConf browser app on iPhone and a test SDK-based application on Windows were able to discover the server.

This is more a warning. Also anyway this was a different server not related to your current app.

Regards

Hi, I want to use SDK client to discover the server, I just modify the Bonjour sample client to test it.
Another question, when I restore the client code and rebuild the application, the sample couldn’t work too.

This is odd. Could you upload here or to support@ your server app + modified sample? I’ll check it to find out goes wrong there.

Hi, I built a test DA application by wizard.
BonjourTest.zip (4.2 MB)

Hello

Some changes need to be made to your client application:
1.You have to assign the ServiceAdded and ServiceRemoved event handlers as

   this.zeroConfBrowser.ServiceAdded += zeroConfBrowser_ServiceAdded;

In your client app you defined the ServiceAdded event handler code but forgot to tie it to the ZeroConfBrowser component.

2.Before accessing the ZeroCong server properties you need to resolve these properties from ZeroConf environment. Thus the proper code of the zeroConfBrowser_ServiceAdded method will be

	private void zeroConfBrowser_ServiceAdded(object sender, ZeroConfBrowseResultEventArgs args)
	{
		ZeroConfService server = args.Record;
		if (server.TryResolve())
		{
			string host = "";
			for (int i = 0; i < server.Addresses.Length; i++)
			{
				if (server.Addresses[i].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
				{
					host = server.Addresses[i].ToString();
					break;
				}
			}
			LogMessage(String.Format("Found server,IP:{0},Port:{1}", host, server.Port));
		}
		else
		{
			LogMessage("Cannot resolve server: " + server.Name);
		}
	}

Note the .TryResolve() method call.


If you don’t mind I would also like to say some notes about the server part.

Currently it looks like

	[STAThread]
	public static int Main(String[] args)
	{
		ApplicationServer server = new ApplicationServer("BonjourTest");

		server.NetworkServer.ServerChannel = new RemObjects.SDK.Server.IpSuperTcpServerChannel();
		server.NetworkServer.Port = 8099;
		server.NetworkServer.ServerMessages[0].Envelopes.Add(new RemObjects.SDK.AesEncryptionEnvelope(@"****"));

        ZeroConfRegistration zeroConf = new ZeroConfRegistration();
        zeroConf.Domain = "local.";
        zeroConf.ServerName = "DiscoverableTestSrv";
        zeroConf.ServerChannel = server.NetworkServer.ServerChannel;

		server.Run(args);
		return 0;
	}

The ApplicationServer class can handle the ZeroConf for you, so this approach can be used:

	[STAThread]
	public static int Main(String[] args)
	{
		ApplicationServer server = new ApplicationServer("BonjourTest");

		server.NetworkServer.ServerChannel = new RemObjects.SDK.Server.IpSuperTcpServerChannel();
		server.NetworkServer.Port = 8099;
		server.NetworkServer.ServerMessages[0].Envelopes.Add(new RemObjects.SDK.AesEncryptionEnvelope(@"****"));
		server.NetworkServer.EnableZeroConf = true;

		server.Run(args);
		return 0;
	}

Also please consider to use SSL/TLS to protect network communications instead of AesEncryptionEnvelope. It has a major issue that ALL clients and servers share the same static password, so it is rather easy to intercept data once this password is obtained. Also it is not that hard to change this password once the client and server apps are deployed. Remoting SDK supports TLS 1.2 which is way more safe than AES envelope and it is very easy to use. SDK can even generate SSL certificates for you or load existing ones (f.e. issued by LetsEncrypt).

Regards