コード例 #1
0
        private void StartServerClient()
        {
            try
            {
                this.receivedCmdContainer = new CommandContainer(containerSize);
                this.toSendCmdContainer   = new CommandContainer(containerSize);

                this.client = new TcpClient();
                this.client.ReceiveBufferSize = ConnectorGlobalSettings.BufferSize;
                this.client.SendBufferSize    = ConnectorGlobalSettings.BufferSize;
                this.client.ReceiveTimeout    = ConnectorGlobalSettings.Timeout;
                this.client.SendTimeout       = ConnectorGlobalSettings.Timeout;

                this.client.Connect(this.connData.Ip, this.connData.Port);

                logger.UpdateLog($"Connected!");
                this.isConnected = true;
            }
            catch (Exception exception)
            {
                this.isConnected = false;
                logger.UpdateLog($"Connection error: {exception.Message}");
            }

            HandleReceivingAsync();
            HandleSendingAsync();
        }
コード例 #2
0
 public void StopConnection()
 {
     try
     {
         this.State = WorkingState.Disabled;
         TcpServer.StopServer();
         _logger.UpdateLog("TCP connection stopped successfully!");
     }
     catch (Exception exception)
     {
         this.State = WorkingState.Error;
         _logger.UpdateLog($"TCP connection - connection stopping error: {exception.Message}");
     }
 }