How to trigger a SubProtocol Command from WebSocketSession method

Sep 4, 2013 at 7:54 PM
Edited Sep 4, 2013 at 7:56 PM
Hi Kerry.
During OnSessionClosed, I need to notify another session using SubProtocol Commands.TRXN formatted message. I'm not sure where the subprotocol instances are exposed. In the sample below, how can I trigger Commands.TRXN on sessionRobotController?
Thank you.
        Protected Overrides Sub OnSessionClosed(reason As CloseReason)
        'Use OSSAppServer.ControllerSession reference so we don't do lookups every time
        Dim sessionRobotController As WebServer.OSSWebSocketSession = CType(Me.AppServer, OSSAppServer).ControllerSession
            If sessionRobotController IsNot Nothing Then
                If sessionRobotController.SessionID = Me.SessionID Then
                    'Robot Controller has disconnected
                    sessionRobotController = Nothing
                ElseIf Me.Role = DEVICE_ROLE.ROBOT Then
                    'Notify Robot Controller that a Robot session has disconnected
                    '-------------------------------------------------
                    'OSS: HowTo send a proper SubProtocol Commands.TRXN "disconnect" instead of plain string message?
                    '-------------------------------------------------
                    sessionRobotController.Send("System: Robot[" & Me.Name & "] disconnected")
                End If
            End If
            'add you logics which will be executed after the session is closed
            MyBase.OnSessionClosed(reason)
        End Sub
Coordinator
Sep 5, 2013 at 4:25 AM
No, you should change your design. You'd better move the message formatting code to the server scope, then you can use it in the session closed handler.