| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 673 人关注过本帖
标题:请教一个关于CSocket的问题
只看楼主 加入收藏
孤月飞星
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-6-23
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
请教一个关于CSocket的问题
我用CSocket类编写了一个客户端和服务端,当我服务端没有打开的时候,客户端的开始链接,connect函数返回的是1。正常情况不是应该服务端开始监听了,客户端才能链接吗?
搜索更多相关主题的帖子: 服务端 客户端 
2013-06-23 16:55
yuccn
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:何方
等 级:版主
威 望:167
帖 子:6815
专家分:42393
注 册:2010-12-16
收藏
得分:20 
connect返回1不就是说明已经连接上了,你查看CSocket的用法才行的,它返回的不是连接成功or 失败


下面from msdn

Return Value

--------------------------------------------------------------------------------


 
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 marked as nonblocking and the connection cannot be completed immediately.
 



Remarks

--------------------------------------------------------------------------------


 
If the socket is unbound, unique values are assigned to the local association by the system, and the socket is marked as bound. Note that if the address field of the name structure is all zeroes, Connect will return zero. To get extended error information, call the GetLastError member function.
 
For stream sockets (type SOCK_STREAM), an active connection is initiated to the foreign host. When the socket call completes successfully, the socket is ready to send/receive data.

For a datagram socket (type SOCK_DGRAM), a default destination is set, which will be used on subsequent Send and Receive calls.

我行我乐
公众号:逻辑客栈
我的博客:
https://blog.yuccn. net
2013-06-24 12:09
快速回复:请教一个关于CSocket的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015860 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved