大家帮看看这么怎么回事:
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 调用中指定的一个未知的无效的或不受支持的选项或层次。"
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 调用中指定的一个未知的无效的或不受支持的选项或层次。"
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货