コード例 #1
0
        //根据条件填充实体,并显示
        private void InitionPortDevice()
        {
            DeviceModel dobj = DeviceObj.GetDeviceModel();
            TcpModel    TCPE = dobj.Port.TCP;
            SerialModel SE   = dobj.Port.Serial;

            if (dobj == null || TCPE == null || SE == null)
            {
                return;
            }
            //显示 端口值
            switch (dobj.Port.PortType)
            {
            case Protocol.Modbus_TCPIPPort: cb_Port.Text = "TCP/IP"; break;

            case Protocol.Modbus_SerialPort: cb_Port.Text = SE.PortName; break;

            case Protocol.Modbus_USBPort: cb_Port.Text = "USB"; break;

            default: break;
            }
            tb_IPadr.Text   = TCPE.IP;
            tb_TCPport.Text = TCPE.Port.ToString();

            cb_BaudRate.Text   = SE.BaudRate.ToString();
            cb_Word.Text       = SE.DataBit.ToString();
            cb_Parit.EditValue = ((int)SE.Parity).ToString();
            cb_stop.EditValue  = ((int)SE.StopBit).ToString();
            tb_WaitTime.Text   = SE.RecoveryWaitTime.ToString();
        }
コード例 #2
0
        public async Task <IActionResult> ExecuteTcp(TcpModel model)
        {
            var method = new BaseCommands
            {
                Method = "Tcp"
            };
            var Variables = new TcpVariables
            {
                Port   = model.Port,
                Length = model.Length
            };
            var FloodModel = new Server.Commands.BaseFloodModel
            {
                Host         = model.Host,
                Time         = model.Time,
                ThreadstoUse = model.ThreadstoUse,
            };
            var Command = new TcpCommand
            {
                newTcpVariables   = Variables,
                newBaseCommand    = method,
                newBaseFloodModel = FloodModel
            };
            var bots = new GetBotsByStatusQuery
            {
                status = model.Force
            };
            var botlist = await _mediator.Send(bots);

            var response = CommandExecute.TcpConnects(botlist, JsonConvert.SerializeObject(Command).Replace(@"\", ""));

            return(Json(response));
        }
コード例 #3
0
        private void LoginBtnClick(object sender, RoutedEventArgs e)
        {
            string id   = idTbx.Text;
            string pass = passTbx.Text;

            TcpModel tcpModel = new TcpModel()
            {
                MSGType = 0,
            };

            if (Properties.Settings.Default.id == id && Properties.Settings.Default.pass == pass)
            {
                if (autoLoginCbx.IsChecked == true)
                {
                    Properties.Settings.Default.isAutoLogin = true;
                    Properties.Settings.Default.Save();
                }
                App.isLogined = true;
                App.TCPManager.PostMessage(tcpModel);
                MessageBox.Show("로그인되었습니다.");
                App.TCPManager.ThreadStart();
                this.Close();
            }
            else
            {
                MessageBox.Show("로그인 실패");
            }
        }
コード例 #4
0
        public string PostMessage(TcpModel tcpModel)
        {
            string json = JsonConvert.SerializeObject(tcpModel);

            this.sendData = Encoding.UTF8.GetBytes(json);

            try
            {
                tcpClient = new TcpClient();
                var result = tcpClient.BeginConnect(ServerIP.serverIP, ServerIP.port, null, null);
                result.AsyncWaitHandle.WaitOne(3000, true);

                networkStream = tcpClient.GetStream();
                networkStream.Write(sendData, 0, sendData.Length);

                tcpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);

                int readData = networkStream.Read(this.responseData, 0, this.responseData.Length);
                Response = Encoding.UTF8.GetString(responseData, 0, readData);

                if (Response == "200")
                {
                    this.isConnection = true;
                }
                return(Response);
            }
            catch (Exception e)
            {
                this.isConnection = false;
                MessageBox.Show("서버와 연결이 끊겨있습니다.");
            }

            return(null);
        }
コード例 #5
0
        public IActionResult TcpView()
        {
            var model = new TcpModel {
                Length       = 32,
                ThreadstoUse = 1000,
                Time         = 60
            };

            return(PartialView("_Tcp", model));
        }
コード例 #6
0
        public void ProcessData(NatSession session, NatRequestInfo requestInfo, TcpModel tcpModel)
        {
            try
            {
                switch (requestInfo.Body.Action)
                {
                case (int)TcpAction.TransferData:
                {
                    //响应请求
                    int count = 0;
mark:
                    var tcpSession = GetSingle(c => c.SessionId == tcpModel.SessionId);
                    if (tcpSession == null)
                    {
                        count++;
                        Thread.Sleep(500);
                        if (count < 5)
                        {
                            goto mark;
                        }
                        HandleLog.WriteLine($"tcpSession【{tcpModel.SessionId}】不存在");
                        return;
                    }
                    //先讲16进制字符串转为byte数组  再gzip解压
                    var response = DataHelper.Decompress(tcpModel.Content);
                    tcpSession.Send(response);
                    HandleLog.WriteLine($"----> {tcpSession.SessionId} 发送报文{response.Length}字节");
                }
                break;

                case (int)TcpAction.Close:
                {
                    //关闭请求
                    var tcpSession = GetSingle(c => c.SessionId == tcpModel.SessionId);
                    if (tcpSession != null)
                    {
                        tcpSession.Close();
                        HandleLog.WriteLine($"连接【{tcpSession.SessionId},{tcpSession.Remote}】关闭成功");
                    }
                }
                break;
                }
            }
            catch (Exception ex)
            {
                HandleLog.WriteLine($"TcpServer穿透处理异常,{ex}");
            }
        }
コード例 #7
0
ファイル: TcpServer.cs プロジェクト: xingx001/SuperNAT
        public void ProcessData(NatSession session, NatRequestInfo requestInfo, TcpModel tcpModel)
        {
            try
            {
                switch (requestInfo.Body.Action)
                {
                case (int)TcpAction.TransferData:
                {
                    //响应请求
                    int count = 0;
mark:
                    var tcpSession = GetSingleSession(c => c.SessionId == tcpModel.SessionId);
                    if (tcpSession == null)
                    {
                        count++;
                        Thread.Sleep(500);
                        if (count < 5)
                        {
                            goto mark;
                        }
                        LogHelper.Warning($"tcpSession【{tcpModel.SessionId}】不存在");
                        return;
                    }
                    //先讲16进制字符串转为byte数组  再gzip解压
                    var response = DataHelper.Decompress(tcpModel.Content);
                    tcpSession.Send(response);
                    LogHelper.Info($"{tcpSession.Map.name} {tcpSession.Map.protocol} {tcpSession.Map.remote_endpoint} --> {tcpSession.Map.local_endpoint} 发送报文{response.Length}字节");
                }
                break;

                case (int)TcpAction.Close:
                {
                    //关闭请求
                    var tcpSession = GetSingleSession(c => c.SessionId == tcpModel.SessionId);
                    if (tcpSession != null)
                    {
                        tcpSession.Close();
                        LogHelper.Info($"连接【{tcpSession.SessionId},{tcpSession.RemoteEndPoint}】关闭成功");
                    }
                }
                break;
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error($"TcpServer穿透处理异常,{ex}");
            }
        }
コード例 #8
0
        //

        #region 设置部分

        public static Boolean SetTcpIP(PortModel PE, TcpModel TCPE)
        {
            return(true);
        }
コード例 #9
0
        public async void GetMessage()
        {
            try
            {
                NetworkStream stream   = tcpClient.GetStream();
                string        response = "";
                int           data     = 0;

                while (true)
                {
                    try
                    {
                        IsSend = false;
                        data   = await stream.ReadAsync(receiveData, 0, receiveData.Length);

                        response = Encoding.UTF8.GetString(receiveData, 0, data);

                        if (!IsSend)
                        {
                            if (!string.IsNullOrEmpty(response))
                            {
                                if (response.IndexOf("총매출액") > -1)
                                {
                                    StatisticCtrl statisticCtrl = (StatisticCtrl)App.UIStateManager.Get(Common.UICategory.STATISTIC);

                                    string totalPrice = "오늘까지의 총매출액은 " + statisticCtrl.TotalStatisticCtrl.TotalPrice + "원 입니다.";

                                    TcpModel tcpModel = new TcpModel()
                                    {
                                        MSGType = 1,
                                        Content = totalPrice,
                                        Group   = true
                                    };

                                    PostMessage(tcpModel);
                                    break;
                                }
                                MessageBox.Show(response);
                            }
                            else
                            {
                                isConnection = false;
                                MessageBox.Show("서버와 연결이 끊겼습니다.");
                                break;
                            }
                        }
                        else
                        {
                            MessageBox.Show("Server Connection Failed");
                            isConnection = false;
                            tcpClient.Close();
                            networkStream.Close();
                            break;
                        }
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Server Connection Failed");
                        isConnection = false;
                        break;
                    }
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.ToString());
            }
        }