我通过以下方式连接到我在另一台服务器上创建的服务:
using (var clientSocket = new TcpClient())
{
...
//Connect async
var result = clientSocket.BeginConnect(hostIP, portNumber, null, null);
//Wait for connection up to our timeout
if (!result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(5)))
{
//This is NEVER run
throw new Exception("Connection timed out.");
}
//It makes it here but shouldn't!
}
如果其他服务器已启动,但侦听端口的服务已关闭,则仍会返回true! (如果服务器已关闭,它会正确抛出异常)
为什么?
如果服务中断(如果没有在该端口上监听),如何使其失败?
答案 0 :(得分:0)
也许您可以使用较新的resize2fs /dev/docker-vg/root resize2fs 1.43.3 (04-Sep-2016)
Filesystem at /dev/docker-vg/root is mounted on/; on-line resizing
required old_desc_blocks = 1, new_desc_blocks = 3 resize2fs:
Permission denied to resize filesystem
方法,甚至允许您提供ConnectAsync
,以防您需要客户端连接任务过早中止。
CancellationToken
答案 1 :(得分:0)
如果没有什么可听的话,似乎没有办法让它失败。相反,您可以使用ReadTimeout
来处理另一端没有任何内容的错误。