Exemplo n.º 1
0
        /// <summary>
        /// Sends a message to peer
        /// </summary>
        /// <param name="message">Message to send</param>
        /// <param name="responseCallback">Callback method, which will be invoked when peer responds</param>
        /// <param name="timeoutSecs">If peer fails to respons within this time frame, callback will be invoked with timeout status</param>
        /// <param name="deliveryMethod">Delivery method</param>
        /// <returns></returns>
        public int SendMessage(IOutgoingMessage message, ResponseCallback responseCallback, int timeoutSecs, DeliveryMethod deliveryMethod)
        {
            if (!IsConnected)
            {
                responseCallback.Invoke(ResponseStatus.NotConnected, null);
                return(-1);
            }

            var id = RegisterAck(message, responseCallback, timeoutSecs);

            SendMessage(message, deliveryMethod);
            return(id);
        }
Exemplo n.º 2
0
        private void SendMessage(IMessage message, ResponseCallback responseCallback,
                                 int timeoutSecs, DeliveryMethod deliveryMethod)
        {
            if (ConnectionState != ConnectionState.Connected)
            {
                responseCallback.Invoke(ResponseStatus.NotConnected, null);
                return;
            }

            RegisterAck(message, responseCallback, timeoutSecs);

            SendMessage(message, deliveryMethod);
        }
Exemplo n.º 3
0
        private static void OnResponse(Response response, ResponseCallback responseCallback)
        {
            switch (response.Result)
            {
            case ERPCResult.Ok:

                Debug.Log($"Login succeed : {response.Args}");
                ClientId = int.Parse(response.Args);

                break;

            case ERPCResult.Error:
                Debug.LogError($"Login failed : {response.Args}");

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            responseCallback?.Invoke(response);
        }