Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
siazon opened this issue Apr 7, 2021 · 0 comments

Comments

@siazon
Copy link

siazon commented Apr 7, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant