aaaaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzzzzzzzzzzzzz
不会吧
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

解决方案 »

  1.   

    是在GUI thread中吗?AfxSocketInit调用过吗
    CSocket只能工作在GUI thread中
      

  2.   

    你的HOST里面填的是什么东西呀?
    如果是十进制表示的IP地址:202.38.64.1,那应该是可以的。
    如果是域名:www.263.net,要做域名转化,查查DNS。 或者在你的子网里不允许连接外边的地址,与防火墙或网关有关。
      

  3.   

    有可能是这样的。在wizzard里面有一项,需要socket支持吗?
    如果没有选,和选了的工程有两点区别:
    1。没有包含afxsock.h头文件
    2。sock没有初始化,一个初始化sock的函数,不先运行的话可以创建,就不能连接了。
      

  4.   

    我只用过CAsyncSocket,没用过CSocket,如果是CAsyncSocket必须先Create,否则会返回WSAENOTSOCKET
    你用GetLastError()看看返回什么错误
      

  5.   

    必须先不带参数的调用Create(),然后Connect()。俺最近正在用CSocket。详情看msdn
      

  6.   

    如果Host就是"某个服务器",那肯定连不上了,应是目的机的IP。还有,目的机也有可能对连接有限制,你可以用返回值看看,到底是什么原因呀。
      

  7.   

    先PING一下试试能不能拼通,然后再调用GetLastError看返回值是什么。
      

  8.   

    我也用了Create了,否则根本编译通不过,我的程序已经编译过了,只是执行的时候连接不上远程主机,错误信息是Server can not connected,但是服务器的确可以连接上呀,我用的也是IP,不是DNS名字呀。
      

  9.   

    在连接之前,请使用套接字(CSocket)初始化函数(AfxSocketInit()),便成功。
      

  10.   

    Nonzero if the function is successful; otherwise 0, and a specific error code can be retrieved by calling GetLastError. If this indicates an error code of WSAEWOULDBLOCK, and your application is using the overridable callbacks, your application will receive an OnConnect message when the connect operation is complete. The following errors apply to this member function: WSANOTINITIALISED   A successful AfxSocketInit must occur before using this API.
    WSAENETDOWN   The Windows Sockets implementation detected that the network subsystem failed.
    WSAEADDRINUSE   The specified address is already in use.
    WSAEINPROGRESS   A blocking Windows Sockets call is in progress.
    WSAEADDRNOTAVAIL   The specified address is not available from the local machine.
    WSAEAFNOSUPPORT   Addresses in the specified family cannot be used with this socket.
    WSAECONNREFUSED   The attempt to connect was rejected.
    WSAEDESTADDRREQ   A destination address is required.
    WSAEFAULT   The nSockAddrLen argument is incorrect.
    WSAEINVAL   Invalid host address.
    WSAEISCONN   The socket is already connected.
    WSAEMFILE   No more file descriptors are available.
    WSAENETUNREACH   The network cannot be reached from this host at this time.
    WSAENOBUFS   No buffer space is available. The socket cannot be connected.
    WSAENOTSOCK   The descriptor is not a socket.
    WSAETIMEDOUT   Attempt to connect timed out without establishing a connection.
    WSAEWOULDBLOCK   The socket is ed as nonblocking and the connection cannot be completed immediately. 
      

  11.   

    少写了一句话!!!!!!!!!!!!
    CSocket m_Server;
    CString Host;
    bool blnConnected;
    Host = "某个服务器";
    m_Server.Create(.....) '参数不太清楚
    blnConnected = m_Server.Connect(Host,80);
    --------> 添上去保证可以!!!!!!!!!!!