在 getsockopt 或 setsockopt 调用中指定的一个未知的、无效的或不受支持的选项或层次

x138138138888 2010-08-23 06:49:53
大家帮看看这么怎么回事:
int port = 159;
string host = "127.0.0.1";
#region
IPAddress ip = IPAddress.Parse(host);
IPEndPoint ipe = new IPEndPoint(ip, port);
Socket s = null;
try
{
s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);//创建一个Socket类
s.Bind(ipe);//绑定端口
s.Listen(10);//开始监听
}
catch (Exception e)
{
Console.Write(e);
}
listBox1.Items.Add("等待连接...");
Socket temp = s.Accept();//为新建连接创建新的Socket。
listBox1.Items.Add("连接已建立...");

string recvStr = "";
byte[] recvBytes = new byte[1024];
int bytes;
bytes = temp.Receive(recvBytes, recvBytes.Length, 0);//从客户端接受信息
recvStr += myEncoding.GetString(recvBytes, 0, bytes);
//MessageBox.Show(recvStr, "服务器端");//把客户端传来的信息显示出来
listBox1.Items.Add("客户端发来的信息:" + recvStr);

string sendStr = "欢迎访问服务器!!";

byte[] bs = myEncoding.GetBytes(sendStr);
temp.Send(bs, bs.Length, 0);//返回客户端成功信息
listBox1.Items.Add("向客户端发送信息:" + sendStr);
temp.Close();
s.Close();


当程序执行到 s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 时就抛
"在 getsockopt 或 setsockopt 调用中指定的一个未知的无效的或不受支持的选项或层次。"

...全文
1304 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhyh3737 2011-11-24
  • 打赏
  • 举报
回复
http://www.cnblogs.com/furenjun/archive/2007/05/15/socketConnectionError.html
hesihai2010 2010-11-26
  • 打赏
  • 举报
回复
楼主怎样解决的啊?
Yhzhtk 2010-11-19
  • 打赏
  • 举报
回复
我也遇到了这个问题啊

111,120

社区成员

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

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

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