为什么不能SetSocketOption??

pdsinfo 2003-04-09 01:47:04

如下程序,我想设置服务器端在3秒内读不到客户的数据就超时,但 //client.SetSocketOption(SocketOptionLevel.Tcp,SocketOptionName.ReceiveTimeout,3000);
这一句没有的话,一切正常(客户用telnet到本机的8888端口,发送一个字符串,回车,服务器收到后显示,退出)
但一旦加上这句话,一旦客户联到服务器,服务器端就异常!!

是:

未处理的异常: System.Net.Sockets.SocketException: 在 getsockopt 或 setsockopt
调用中指定的一个未知的、无效的或不受支持的选项或层次。
at System.Net.Sockets.Socket.SetSocketOption(SocketOptionLevel optionLevel, S
ocketOptionName optionName, Int32 optionValue)
at Test.Main() in d:\documents and settings\administrator\桌面\consoleapplica
tion1\class1.cs:line 15

为什么呢???高手救命!!
================以下为程序===============

using System;
using System.Collections;
using System.Net.Sockets;
using System.Threading;
using System.Text;
using System.IO;
class Test
{
public static void Main()
{
TcpListener server=new TcpListener(8888);
server.Start();
Socket client=server.AcceptSocket();

//client.SetSocketOption(SocketOptionLevel.Tcp,SocketOptionName.ReceiveTimeout,3000);

NetworkStream ns=new NetworkStream(client,FileAccess.ReadWrite,true);
StreamReader sr=new StreamReader(ns,Encoding.Default);
string sRecv=sr.ReadLine();
Console.WriteLine("Client says:"+sRecv);
sr.Close();
ns.Close();
client.Close();
server.Stop();


}
}
...全文
284 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
pdsinfo 2003-04-13
  • 打赏
  • 举报
回复
十分感激!!!!!
whxbb 2003-04-11
  • 打赏
  • 举报
回复
client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout,3000);

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧