zhaopeiym / IoTClient

This is an IoT device communication protocol implementation client, which will include common industrial communication protocols such as mainstream PLC communication reading, ModBus protocol, and Bacnet protocol. This component is open source and free for life, using the most relaxed MIT open source agreement, you can modify and commercial use at will (commercial use please evaluate and test). 这是一个物联网设备通讯协议实现客户端,将会包括主流PLC通信读取、ModBus协议、Bacnet协议等常用工业通讯协议。本组件终身开源免费,采用最宽松的MIT开源协议,您可以随意修改和商业使用(商业使用请做好评估和测试)。

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

在TCPserver没有应答的情况下socketTcp重连异常,导致致命性错误

siazon opened this issue · comments

OtherControl,114行

private void but_tcpSend_Click(object sender, EventArgs e)
        {
            try
            {
                var command = DataConvert.StringToByteArray(txt_tcpmsg.Text, false);
                socketTcp.Send(command);
                var msg = SocketRead(socketTcp, 4096);
                AppendText(msg.ByteArrayToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                //重新连接
                socketTcp?.Close();
                socketTcp.Connect(new IPEndPoint(IPAddress.Parse(txt_tcpip.Text?.Trim()), int.Parse(txt_tcpport.Text?.Trim())));
            }
        }

应该再包一层try 或者用非阻塞的方式Receive