/// <summary> /// Creates controller proxy and establishes connection. /// </summary> /// <param name="endpointAddress"> /// Endpoint address (ip:port). <see cref="APIClient.ConnectToControllerProxy">Should be requested from control connection</see>. /// </param> /// <param name="keepAlive"> /// True if automatic pings should keep connection alive even if caller doesn't send data. /// </param> public ControllerProxy(string endpointAddress, bool keepAlive = false) : base(endpointAddress, keepAlive) { controller = new ControllerStateRequest() { Origin = (byte)ControllerOrigin.Zero, TaskType = (byte)ControllerTask.SendFullState }; }
/// <summary> /// Creates controller proxy and establishes connection. /// </summary> /// <param name="endpointAddress"> /// Endpoint address (ip:port). <see cref="APIClient.ConnectToControllerProxy">Should be requested from control connection</see>. /// </param> /// <param name="keepAlive"> /// True if automatic pings should keep connection alive even if caller doesn't send data. /// </param> public ControllerProxy(string endpointAddress, bool keepAlive = false) : base(endpointAddress, keepAlive) { controller = new ControllerStateRequest() { TaskType = (byte)ControllerTask.SendFullState, Version = ControllerStateRequest.CurrentVersion }; }
/// <summary> /// Disconnected from controller API and frees the API for other clients. /// </summary> public void Disconnect() { var disconnectRequest = new ControllerStateRequest() { TaskType = (byte)ControllerTask.Disconnect }; try { SendMessage(disconnectRequest); } catch (TimeoutException) { // Connection probably dropped another way, ignoring } catch (FiniteStateMachineException) { // Connection state invalid, close anyway } CloseSocket(); }
private ControllerStateResponse SendMessage(ControllerStateRequest obj) => SendMessage <ControllerStateResponse>(obj);