public override void OnInspectorGUI()
    {
        client      = (TCPClient)target;
        client.host = EditorGUILayout.TextField("Host: ", client.host);
        client.port = EditorGUILayout.IntField("Port: ", client.port);

        client.message = EditorGUILayout.TextField("Message: ", client.message);
        client.msgType = EditorGUILayout.TextField("Message Type: ", client.msgType);

        EditorGUILayout.Space();
        SerializedProperty pcdWriter = serializedObject.FindProperty("pcdWriter");

        EditorGUILayout.PropertyField(pcdWriter, new GUIContent("PCDWriter"), true);
        serializedObject.ApplyModifiedProperties();

        if (GUILayout.Button("Connect to server"))
        {
            client.ConnectToServerAsync();
        }

        if (GUILayout.Button("Send message"))
        {
            client.SendMessageToNet(client.message, client.msgType);
        }

        if (GUILayout.Button("Send PCD"))
        {
            client.SendPointCloud();
        }

        if (GUILayout.Button("Disconnect"))
        {
            client.Disconnect();
        }
    }
Exemple #2
0
 private void Conn()
 {
     if (this.tcp != null)
     {
         //连接到服务器
         SocketErrorCodes codes = tcp.ConnectToServerAsync(this.TCPClientConnectCallback);
     }
 }
Exemple #3
0
        //-------------------------------------//
        //    Function | DeviceConnect
        // Description | Attempts to connect to remote device.
        //-------------------------------------//

        internal static void DeviceConnect()
        {
            try {
                client.ConnectToServerAsync(clientConnect);
            } catch (Exception _er) {
                ErrorLog.Error("Error connecting to CoolMaster device at address {0}: {1}", ipa, _er);
            }
        }
Exemple #4
0
    // method to handle client socket status
    void SocketStatusChange(TCPClient myTCPClient, SocketStatus clientSocketStatus)
    {
        Debug(String.Format("[PJLink Projector] LAN client ({1}) reports: {0}", clientSocketStatus, IPaddress));

        if (clientSocketStatus == SocketStatus.SOCKET_STATUS_CONNECTED)
        {
            CrestronEnvironment.Sleep(2000);
            Connected = true;
            Debug("SOCKET CONNECTED!");
        }
        else
        {
            Connected = false;
            CrestronEnvironment.Sleep(2000); //attempt reconnect after 2 seconds
            Client.ConnectToServerAsync(ConnectCallBack);
        }
    }
        //-------------------------------------//
        //    Function | ServerConnect
        // Description | Attempts to connect to server.
        //-------------------------------------//

        internal static void ServerConnect()
        {
            try {
                serverConnecting = true;
                client.ConnectToServerAsync(clientConnect);
                reconnectTimer = new CTimer(reconnectTimerHandler, 15000);
            } catch (Exception _er) {
                ErrorLog.Error("[ERROR] Error connecting to DIS at address {0}: {1}", serverIp, _er);
            }
        }
Exemple #6
0
 internal void ClientConnectToServerAsync()
 {
     if (EnableSSL)
     {
         SSLClient.ConnectToServerAsync(ConnectToServerSSLCallback);
     }
     else
     {
         NoSSLClient.ConnectToServerAsync(ConnectToServerNoSSLCallback);
     }
 }
 // client connect callback method
 void PJLinkConnectCallBack(TCPClient Client)
 {
     if (Client.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED)
     {
         Client.ReceiveDataAsync(PJLinkReceiveDataCallback); // set up callback when data received
     }
     else
     {
         CrestronEnvironment.Sleep(2000);
         Client.ConnectToServerAsync(PJLinkConnectCallBack);  // connection failed, try again
     }
 }
    public void PJLinkInitialise(string IP)
    {
        IPaddress = IP;
        Debug("Initialising Client for PJLink Projector @ " + IPaddress);

        Client = new TCPClient(IPaddress, Port, BufferSize);
        Client.SocketStatusChange += new TCPClientSocketStatusChangeEventHandler(PJLinkSocketStatusChange);
        Client.ConnectToServerAsync(PJLinkConnectCallBack);

        PollPowerTimer     = new CTimer(PJLinkPollPower, null, 3000, 3000);      //start 3 second timer to check power state
        PollSourceTimer    = new CTimer(PJLinkPollSource, null, 20000, 20000);   //start 20 second timer to check current source
        PollLampHoursTimer = new CTimer(PJLinkPollLamp, null, 300000, 300000);   //start 30 minute second timer to check lamp hours
    }
        /// <summary>
        /// connect to server and listen for data
        /// </summary>
        public void Connect()
        {
            SocketErrorCodes err = new SocketErrorCodes();

            if (_initialized)
            {
                try
                {
                    _manualDisconnect = false;
                    err = _tcpClient.ConnectToServerAsync(ConnectToServerCallback);
                    Debug("Connection attempt: " + _tcpClient.AddressClientConnectedTo, ErrorLevel.Notice, err.ToString());
                }
                catch (Exception e)
                {
                    Debug(e.Message, ErrorLevel.Error, err.ToString());
                }
            }
            else
            {
                Debug("TCPClient not initialized, missing data", ErrorLevel.Notice, err.ToString());
            }
        }
Exemple #10
0
 // client connect callback method
 void ConnectCallBack(TCPClient Client)
 {
     if (Client.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED)
     {
         Client.ReceiveDataAsync(ReceiveDataCallback); // set up callback when data received
     }
     else
     {
         CrestronEnvironment.Sleep(2000);
         Client.ConnectToServerAsync(ConnectCallBack);  // connection failed, try again
         CrestronConsole.PrintLine("Attempting to reconnect PJLink Projector");
     }
 }
 /// <summary>
 /// Connect the client
 /// </summary>
 /// <param name="shouldReconnect">Set to true to stay connected</param>
 public void Connect(bool shouldReconnect)
 {
     _shouldReconnect = shouldReconnect;
     if (_connectFailCount == 0)
     {
         ErrorLog.Notice("{0}.Connect(shouldReconnect = {1})", this.GetType().Name, shouldReconnect);
     }
     if (Connected)
     {
         ErrorLog.Warn("{0}.Connect() ... allready connected!", this.GetType().Name);
     }
     else
     {
         _client.ConnectToServerAsync(OnConnectResult);
     }
 }
Exemple #12
0
        public int Connect(String IPAddress, int port, int buffersz)
        {
            if (bDebug)
            {
                CrestronConsole.PrintLine("Connect({0},{1},{2})", IPAddress, port, buffersz);
            }

            Pacer.Chunk_Size = buffersz;
            client           = new TCPClient(IPAddress, port, 4096);

            SocketErrorCodes err = client.ConnectToServerAsync(myConnectCallback);

            if (bDebug)
            {
                CrestronConsole.PrintLine("Connect() - " + err);
            }

            return(Convert.ToInt32(err));
        }
        /// <summary>
        /// Connect Method. Will return if already connected. Will write errors if missing address, port, or unique key/name.
        /// </summary>
        public void Connect()
        {
            ConnectionCount++;
            Debug.Console(2, this, "Attempting connect Count:{0}", ConnectionCount);


            if (IsConnected)
            {
                Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Already connected. Ignoring.");
                return;
            }
            if (IsTryingToConnect)
            {
                Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Already trying to connect. Ignoring.");
                return;
            }
            try
            {
                IsTryingToConnect = true;
                if (RetryTimer != null)
                {
                    RetryTimer.Stop();
                    RetryTimer = null;
                }
                if (string.IsNullOrEmpty(Hostname))
                {
                    Debug.Console(0, this, Debug.ErrorLogLevel.Warning, "DynamicTcpClient: No address set");
                    return;
                }
                if (Port < 1 || Port > 65535)
                {
                    Debug.Console(0, this, Debug.ErrorLogLevel.Warning, "DynamicTcpClient: Invalid port");
                    return;
                }
                if (string.IsNullOrEmpty(SharedKey) && SharedKeyRequired)
                {
                    Debug.Console(0, this, Debug.ErrorLogLevel.Warning, "DynamicTcpClient: No Shared Key set");
                    return;
                }

                // clean up previous client
                if (Client != null)
                {
                    Cleanup();
                }
                DisconnectCalledByUser = false;

                Client = new TCPClient(Hostname, Port, BufferSize);
                Client.SocketStatusChange += Client_SocketStatusChange;
                if (HeartbeatEnabled)
                {
                    Client.SocketSendOrReceiveTimeOutInMs = (HeartbeatInterval * 5);
                }
                Client.AddressClientConnectedTo = Hostname;
                Client.PortNumber = Port;
                // SecureClient = c;

                //var timeOfConnect = DateTime.Now.ToString("HH:mm:ss.fff");

                ConnectFailTimer = new CTimer(o =>
                {
                    Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Connect attempt has not finished after 30sec Count:{0}", ConnectionCount);
                    if (IsTryingToConnect)
                    {
                        IsTryingToConnect = false;

                        //if (ConnectionHasHungCallback != null)
                        //{
                        //    ConnectionHasHungCallback();
                        //}
                        //SecureClient.DisconnectFromServer();
                        //CheckClosedAndTryReconnect();
                    }
                }, 30000);

                Debug.Console(2, this, "Making Connection Count:{0}", ConnectionCount);
                Client.ConnectToServerAsync(o =>
                {
                    Debug.Console(2, this, "ConnectToServerAsync Count:{0} Ran!", ConnectionCount);

                    if (ConnectFailTimer != null)
                    {
                        ConnectFailTimer.Stop();
                    }
                    IsTryingToConnect = false;

                    if (o.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED)
                    {
                        Debug.Console(2, this, "Client connected to {0} on port {1}", o.AddressClientConnectedTo, o.LocalPortNumberOfClient);
                        o.ReceiveDataAsync(Receive);

                        if (SharedKeyRequired)
                        {
                            WaitingForSharedKeyResponse = true;
                            WaitForSharedKey            = new CTimer(timer =>
                            {
                                Debug.Console(1, this, Debug.ErrorLogLevel.Warning, "Shared key exchange timer expired. IsReadyForCommunication={0}", IsReadyForCommunication);
                                // Debug.Console(1, this, "Connect attempt failed {0}", c.ClientStatus);
                                // This is the only case where we should call DisconectFromServer...Event handeler will trigger the cleanup
                                o.DisconnectFromServer();
                                //CheckClosedAndTryReconnect();
                                //OnClientReadyForcommunications(false); // Should send false event
                            }, 15000);
                        }
                        else
                        {
                            //CLient connected and shared key is not required so just raise the ready for communication event. if Shared key
                            //required this is called by the shared key being negotiated
                            if (IsReadyForCommunication == false)
                            {
                                OnClientReadyForcommunications(true); // Key not required
                            }
                        }
                    }
                    else
                    {
                        Debug.Console(1, this, "Connect attempt failed {0}", o.ClientStatus);
                        CheckClosedAndTryReconnect();
                    }
                });
            }
            catch (Exception ex)
            {
                Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Client connection exception: {0}", ex.Message);
                IsTryingToConnect = false;
                CheckClosedAndTryReconnect();
            }
        }