tcpclient连接超时怎么设置?
解决方案 »
- 关于C#取得Ip数据包后数据分析请教
- ASP.NET SQL 2005 C# 相册图片绑定不能正确显示
- 【紧急求助】请大家共享一份学校名单 或者给个链接 50分
- 确保方法的参数的格式正确。将一个字符串转换为datatime时,先分析该字符串以获取的日期,然后再将每个变量放置到datetime对象中。获取此异常的常规帮助。?
- c#操作word,怎么根据实际情况生成第二或者第N页
- List<>作为参数传的时候为什么报错啊?
- 程序编译通不过,请高人指点!
- 对象间如何通信最好
- xml查询问题。快来~~~~~ ^_^
- 如何在Form中动态生成几个checkbox?
- 正则表达式取<script src=></script>中的src部分内容!
- 在asp.net中使用AdRotator 广告控件的问题 C#
获取或设置 TcpClient 等待发送操作成功完成的时间量。
属性值
发送超时值(以毫秒为单位)。默认为 0。
备注
SendTimeout 属性确定 Send 方法在成功返回之前阻塞的时间量。这一时间的度量单位为毫秒。
调用 Write 方法以后,基础 Socket 返回实际发送到主机的字节数。SendTimeout 属性确定 TcpClient 在接收返回的字节数之前所等待的时间量。如果超时在 Send 方法成功完成之前过期,TcpClient 将引发 SocketException。默认为无超时。
示例
[Visual Basic, C#] 以下示例设置和获取 SendTimeout 值。
[Visual Basic]
' Sets the send time out using the SendTimeout public property.
tcpClient.SendTimeout = 5' Gets the send time out using the SendTimeout public property.
If tcpClient.SendTimeout = 5 Then
Console.WriteLine(("The send time out limit was successfully set " + tcpClient.SendTimeout.ToString()))
End If
[C#]
// sets the send time out using the SendTimeout public property.
tcpClient.SendTimeout = 5;// gets the send time out using the SendTimeout public property.
if (tcpClient.SendTimeout == 5)
Console.WriteLine("The send time out limit was successfully set " +
tcpClient.SendTimeout.ToString());
获取或设置在初始化一个读取操作以后 TcpClient 等待接收数据的时间量。
属性值
连接的超时值(以毫秒为单位)。默认值为 0。
备注
ReceiveTimeout 属性确定 Read 方法在能够接收数据之前保持阻塞状态的时间量。这一时间的度量单位为毫秒。如果超时在 Read 成功完成之前到期,TcpClient 将引发 SocketException。默认为无超时。
示例
[Visual Basic, C#] 以下示例设置和获取接收超时。
[Visual Basic]
' Sets the receive time out using the ReceiveTimeout public property.
tcpClient.ReceiveTimeout = 5' Gets the receive time out using the ReceiveTimeout public property.
If tcpClient.ReceiveTimeout = 5 Then
Console.WriteLine(("The receive time out limit was successfully set " + tcpClient.ReceiveTimeout.ToString()))
End If
[C#]
// Sets the receive time out using the ReceiveTimeout public property.
tcpClient.ReceiveTimeout = 5;// Gets the receive time out using the ReceiveTimeout public property.
if (tcpClient.ReceiveTimeout == 5)
Console.WriteLine("The receive time out limit was successfully set " +
tcpClient.ReceiveTimeout.ToString());
忘了说了我是在 .NET Framework 精简版下用的,没有TcpClient.SendTimeout和TcpClient.ReceiveTimeout 属性
socketEvent.WaitOne(5000,true);
超过等待时间就退出重新执行