高手们,俺想请问。。。。。。

hanutao 2002-04-21 02:00:21
using System;
using System.Net;
using System.Net.Sockets;

class mainprocess
{
static void Main()
{
try
{
IPEndPoint host=new IPEndPoint(IPAddress.Parse("172.16.1.30"),80);
Socket s=new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
s.Bind(host);
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
}

用csc编译通过,但在执行时出现错误信息;参考的对象种类不支持尝试的操作。
请问错出在哪里?
...全文
48 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
hanutao 2002-04-22
  • 打赏
  • 举报
回复
真是千里寻知音呀,谢谢 aimstrong(今生今世)
问题解决了,散分
aimstrong 2002-04-21
  • 打赏
  • 举报
回复
我跟踪了一下你的程序,发现可能是下面两个错误:
ErrorCode 10048--你很可能试图用一个已经被使用的IP地址/端口
ErrorCode 10049--你试图用非本机的IP

下面是msdn的详解:
WSAEADDRINUSE (10048)
Address already in use.
Typically, only one usage of each socket address (protocol/IP address/port) is permitted. This error occurs if an application attempts to bind a socket to an IP address/port that has already been used for an existing socket, or a socket that was not closed properly, or one that is still in the process of closing. For server applications that need to bind multiple sockets to the same port number, consider using setsockopt(SO_REUSEADDR). Client applications usually need not call bind at all—connect chooses an unused port automatically. When bind is called with a wildcard address (involving ADDR_ANY), a WSAEADDRINUSE error could be delayed until the specific address is committed. This could happen with a call to another function later, including connect, listen, WSAConnect, or WSAJoinLeaf.

WSAEADDRNOTAVAIL (10049)
0ACannot assign requested address.
The requested address is not valid in its context. This normally results from an attempt to bind to an address that is not valid for the local machine. This can also result from connect, sendto, WSAConnect, WSAJoinLeaf, or WSASendTo when the remote address or port is not valid for a remote machine (for example, address or port 0).
hanutao 2002-04-21
  • 打赏
  • 举报
回复
败了,自刎
hanutao 2002-04-21
  • 打赏
  • 举报
回复
救命呀,俺一直在线守侯了近两个小时了
hanutao 2002-04-21
  • 打赏
  • 举报
回复
早已装过了
srnld 2002-04-21
  • 打赏
  • 举报
回复
你装了TCP协议没?
hanutao 2002-04-21
  • 打赏
  • 举报
回复
再加20
各位高手,这个问题困惑好久了,帮帮忙
hanutao 2002-04-21
  • 打赏
  • 举报
回复
请回答

110,538

社区成员

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

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

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