How can I debug a background plugin?

Hi,

I am trying to establish a WebSocket connection in my background plugin to send messages to either the client or the admin plugin using the Milestone SDK (VideoOS.Platform.Messaging). However, when I run the application in debug mode, the background service fails to connect, and I cannot debug it because the breakpoints do not get hit. Interestingly, the same code works perfectly when I use it in my client plugin.

Any advice ?

If you are not hitting the breakpoints when debugging a plugin, it may indicate that you are not loading the latest build when running the application. The MIP SDK documentation provides a description on how to debug plugin code, which can be found in the Start Debugging from Visual Studio section on the Plug-in development page. Please ensure you follow the instructions provided there.

I believe the issue might be that I needed to debug using the EventServer.exe, as the background plugin uses the event server by default.

  1. not loading the latest build: I confirmed that I am running the latest version because the same code triggers a breakpoint inside the client plugin.

I am experiencing an issue with the SDK messaging. How can I send a message from the background and receive it on the client side?

To send a message from a plugin running in the Event Server and receive it on the client side, use MIP message communication. For more details, refer to the documentation here. Relevant samples are listed at the bottom of the page.

Debugging a plugin running in the Event Server differs from debugging a plugin running in a client application. It is described in Start the debugging (note 2) subsection on the documentation page linked above.

Correct. I missed this; thank you very much for the feedback.

I do have one question regarding the MIP Messaging. In the code below, we can start the communication between MIP environments, but I have set up a websocket inside the background plugin from which I want to send the message to my client.

MessageCommunicationManager.Start(EnvironmentManager.Instance.MasterSite.ServerId)

Do you have any advice on how I would go about it? I’m not sure if the communication manager should also be started inside the background plugin.

You mentioned having a websocket inside the background plugin. Does it mean you use WebSockets Messages API, which is utilized by Chat with WebSockets sample (see here)? If so, you should stick to using it in both your client and background plugins. In that case, you should not use MessageCommunicationManager at all. Instead, you should use MessageClientManager.

If you don’t use WebSockets Messages API, then you can start the MessageCommunicationManager in your background plugin, and it should just be ignored if another plugin already started it.

        public override void Init()
        {
            _stop = false;
            _thread = new Thread(new ThreadStart(Run));
            _thread.Name = "TestLPR Background Thread";
            _thread.Start();
 
            MessageCommunicationManager.Start(EnvironmentManager.Instance.MasterSite.ServerId);
            _messageCommunication = MessageCommunicationManager.Get(EnvironmentManager.Instance.MasterSite.ServerId);
            _messageCommunication.TransmitMessage(message, null, null, null);
 
   //EnvironmentManager.Instance.SendMessage(message); //This only works if  EnvironmentType is == SmartClient
        }
 
 Message message = new Message("MyMessageId", "Hello, world!");

So I tried the above code but at line 10 I get the following error:

VideoOS.Platform.MIPException: 'Unable to connect to EventServer.CommunicationService'
 
Inner Exception:
CommunicationMIPException: GetRegisteredServiceUriInfo: Could not get hold of the services - 
 
RestApiMIPException: GET Unexpected statuscode BadRequest in 'http://****/API/rest/v1/registeredServices?VMSinternal=' - Bad request: Value cannot be null.
Parameter name: token

My thought is that if I set the FQIDs to null, the message will be sent to all listening to the filter. So I’m not sure if this might be the issue ?

I created a WebSocket to receive specific data and notifications from external API.

The issue causing the error could be that MessageCommunicationManager takes some time to get fully started if it has not already been started. There is boolean property IsConnected on MessageCommunication, and you should aim to send message only when this is true.

You are correct that if FQID of destination endpoint is set to null, then the message will be sent to all listening to the filter, so that should not be an issue.

Hi @Paulina Bien

Have you encountered examples where the background plugin operates within the `EnvironmentType.Service` environment and communicates with the client plugin?

In the MIP plugin examples, I have only seen the background running in the SmartClient environment when they utilized the MessageCommunicationManager.

You are right; there are no samples showing how to send a message from a background plugin, but it shouldn’t be different from a client plugin.

Have you managed to make your plugin work? If not, I would suggest looking into the Chat sample, particularly the implementation of ChatSidePanelWpfUserControl. There, you will find a ConnectionStateChangedEvent handler that handles sending a message once the communication is established. I noticed you don’t have it in the code you posted above.