⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_23831.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:23831 发表者:Shadow_wsh 发表日期:2002-12-06 18:33:15
<br>主题:socket的连接时间问题?
<br>内容:s = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);<BR>if (s != INVALID_SOCKET) <BR>{<BR>&nbsp;&nbsp; int nPort=8000;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp; struct&nbsp;&nbsp;sockaddr_in sa_in;<BR>&nbsp;&nbsp; sa_in.sin_family=AF_INET;<BR>&nbsp;&nbsp; sa_in.sin_port=nPort;<BR>&nbsp;&nbsp; sa_in.sin_addr.S_un.S_addr=inet_addr(sIPAddress);<BR>&nbsp;&nbsp; if(connect(s, (LPSOCKADDR)&amp;sa_in, sizeof(sa_in))== NO_ERROR)<BR>&nbsp;&nbsp;{}<BR>}<BR><BR>通常在无法连接服务端的时,connect的时间为30--40s,请问如何能控制这个事件的返回时间?<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:深四 回复日期:2002-12-06 18:50:23
<br>内容:请使用 GetTickCount ,WSAGetLastError,
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:John Lan 回复日期:2002-12-06 20:17:32
<br>内容:use nonblocking socket, and build a timer to check the timeout.<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:Shadow_wsh 回复日期:2002-12-08 14:31:35
<br>内容:可是nonblocking socket始终返回的是ERROR!<BR>具体应该怎么处理请告知,谢谢!
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:未出手的飞刀 回复日期:2002-12-08 19:27:06
<br>内容:<BR>使用非阻塞的不断去connect直到成功,或者在规定时间内connect不成功就放弃退出
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:Shadow_wsh 回复日期:2002-12-09 10:43:42
<br>内容:不断去connect,可基本上不会返回成功值,而且不能一直去连或者放弃,因为用在实时系统中
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:John Lan 回复日期:2002-12-10 00:24:41
<br>内容:摘自MSDN, 我就不翻译了 , :-)<BR>---------------------------------------------------------------------------------------------------------<BR>With a nonblocking socket, the connection attempt cannot be completed immediately. In this case, connect will return SOCKET_ERROR, and WSAGetLastError will return WSAEWOULDBLOCK. In this case, there are three possible scenarios: <BR><BR>1:<BR>Use the *select* function to determine the completion of the connection request&nbsp;&nbsp;by checking to see if the socket is writeable. <BR><BR>2:<BR>If the application is using *WSAAsyncSelect* to indicate interest in connection events, then the application will receive an FD_CONNECT notification indicating that the connect operation is complete (successfully or not). <BR><BR>3:<BR>If the application is using *WSAEventSelect* to indicate interest in connection events, then the associated event object will be signaled indicating that the connect operation is complete (successfully or not). <BR>------------------------------------------------------------------------------------------------------------<BR>2002-12-10 0:25:50

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -