示例#1
0
 public void Disconnect()
 {
     if (ClientTcp.Connected)
     {
         Mode = MODES.Disconnected.ToString();
         ModbusPoolingTask.Abort();
         ModBusMaster.Dispose();
         ClientTcp.Close();
         Redresseurs = null;
     }
 }
示例#2
0
    //关闭服务
    private void OnApplicationQuit()
    {
        print("OnApplicationQuit");
        if (SceneFlag == 1)
        {
            PlayerInfo.Instance.SendPlayerInfo();
            GManager.Instance.SendMessageByTcp("E1 " + UIManager.account + " ");
            GManager.Instance.SendMessageByUdp("E1 " + UIManager.account + " ");
        }

        ClientTcp.Close();
        ClientUDP.Close();
    }
示例#3
0
        protected override void Run()
        {
            bool   foundService   = false;
            string requestMessage = "mpos_serv_req_wp:" + appName + ":" + appVersion;

            while (running && !foundService)
            {
                Debug.WriteLine("#> [DiscoveryService]: Started Discovery Service for endpoint: " + server.Type + " and app: " + appName + "/" + appVersion);
                foundService = true;

                ClientTcp socket = null;
                try
                {
                    socket = new ClientTcp(256, false);
                    if (server.Type == EndpointType.SECONDARY_SERVER && !MposFramework.Instance.DeviceController.IsOnline())
                    {
                        throw new ConnectException("The mobile is completly offline!");
                    }

                    socket.Connect(server.Ip, servicePort);
                    Sent(socket, requestMessage);
                    Receive(socket);
                }
                catch (Exception e)
                {
                    Debug.WriteLine("## [DiscoveryService]: Error -> \n" + e.ToString());
                    foundService = false;
                }
                finally
                {
                    if (running && !foundService)
                    {
                        Debug.WriteLine(">> [DiscoveryService]: Retry Discovery Service for endpoint: " + server.Type + ", in " + EndpointController.REPEAT_DISCOVERY_TASK + " ms");
                        Thread.Sleep(EndpointController.REPEAT_DISCOVERY_TASK);
                    }
                    else
                    {
                        Debug.WriteLine("#> [DiscoveryService]: Finished Discovery Service for endpoint: " + server.Type + " on " + server.Ip);
                        MposFramework.Instance.EndpointController.StartDecisionMaker(server);
                    }

                    socket.Close();
                }
            }
        }
示例#4
0
        protected override void Run()
        {
            Debug.WriteLine("#> [DeployRpcService]: Started Deploy App " + appName + "/" + appVersion + " on Remote Server (" + server.Ip + ":" + server.DeployAppPort + ")");
            ClientTcp socket = null;

            //async programming, but run synch mode
            task = new DependenceFileLoadTask();
            task.RunSynchronous();

            try
            {
                socket = new ClientTcp(false);
                socket.Connect(server.Ip, server.DeployAppPort);

                string deployRequest = "mpos_deploy_app:" + appName + ":" + appVersion;
                //Debug.WriteLine("[DEBUG]: sent -> " + deployRequest);
                Sent(socket, deployRequest);
                if (!ReceiveFeedbackMessage(socket))
                {
                    throw new NetworkException("Problems in deploy request");
                }

                string mposDependence = "mpos_dependence_size:" + task.dependenceFiles.Count;
                //Debug.WriteLine("[DEBUG]: sent -> " + mposDependence);
                Sent(socket, mposDependence);
                if (!ReceiveFeedbackMessage(socket))
                {
                    throw new NetworkException("Problems in deploy request");
                }

                SentFiles(socket);
                server.RpcServicePort = ReceiveServicePort(socket);
            }
            catch (Exception e)
            {
                Debug.WriteLine("## [DeployRpcService]: Any problem in I/O processing!\n" + e.ToString());
            }
            finally
            {
                Debug.WriteLine("#> [DeployRpcService]: Finished Deploy App " + appName + "/" + appVersion + " on Remote Server port: " + server.RpcServicePort);
                socket.Close();
            }
        }
示例#5
0
        public object Call(bool needProfile, bool manualSerialization, Object objOriginal, String methodName, object[] methodParams)
        {
            ClientTcp socket = null;

            if (server == null)
            {
                throw new NetworkException("Need to setup any server for use the RPC Client");
            }

            try
            {
                socket = new ClientTcp();
                socket.Connect(server.Ip, server.RpcServicePort);

                Sent(socket, manualSerialization, needProfile, objOriginal, methodName, methodParams);
                ResponseRemotable response = Receive(socket, objOriginal, methodName);

                if (response.Code == Code.OK)
                {
                    return(response.MethodReturn);
                }
                else if (response.Code == Code.METHOD_THROW_ERROR)
                {
                    throw new RpcException("[Server]: Remote method thrown some errors\n" + response.Except);
                }
                else
                {
                    throw new RpcException("[Server]: RPC call terminated with some errors!\n" + response.Except);
                }
            }
            catch (SocketException e)
            {
                throw new ConnectException("Failed to connect to server: " + server.Ip + ":" + server.RpcServicePort, e);
            }
            finally
            {
                socket.Close();
            }
        }
示例#6
0
 private void OnApplicationQuit()
 {
     client.Close();
 }