c# socket 断线重连

https://blog.csdn.net/thebestleo/article/details/52354126

里面有socket的封装类

但是没有使用的代码,在这里补充一下

服务器端主动断开连接,客户端会抛出异常,并会设置连接状态 IsconnectSuccess 为false,但不会自动重连,所以加了一个timer

Socket_wrapper.remoteHost="127.0.0.1";
            Socket_wrapper.remotePort = 9601;
            Socket_wrapper.checkSocketState();

            timer = new Timer();
            timer.Interval = 30 * 1000;
            timer.Tick += Timer_Tick;
            timer.Start();
private void Timer_Tick(object sender, EventArgs e)
        {
            Socket_wrapper.checkSocketState();
        }

猜你喜欢

转载自blog.csdn.net/zhangsansecond/article/details/87286600