Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Ò»¸öÆæ¹ÖµÄÎÊÌâ

0 views
Skip to first unread message

无怨无悔

unread,
Oct 26, 1999, 3:00:00 AM10/26/99
to
> [1;36m==> Ph_Li(罗马假日) 说道: [37;40m [0m
> ^^^^^
> 若无错误发生,则connect()返回0。
>

No,MSDN tells me that nonzero if the function is successful.

I think the problem is not here,but I don't know where.

I have corrected this program by override OnConnect(....),

though Connect returns 0,OnConnect reports no problem,

I don't know why.

Thanks.

--
※ 来源: 中国科大BBS站 [bbs.ustc.edu.cn]

罗.比亚吉奥

unread,
Oct 26, 1999, 3:00:00 AM10/26/99
to
> [1;36m==> Nicky_Sun(无怨无悔) 说道: [37;40m [0m
> m_psock=new CClientsock(this);
> if(!m_psock->Create()){
> AfxMessageBox("Client connect server error!");
> int err=m_psock->GetLastError();
> char buf[10];
> gcvt(err,10,buf);
> AfxMessageBox(buf);
> }
> BOOL ret=m_psock->Connect("202.119.25.233",5050);
> if(!ret){
> AfxMessageBox("Client connect server error!");
> int err=GetLastError();

GetLastError() returns last Win32 API's error code,
so you should immediately call it before another Win32 API
is called.But here you called AfxMessageBox() and it internally
call Win32 API:MessageBox(),so the error code you got was the
result of AfxMessageBox(),not Connect().2nd point,I think you
should call WSAGetLastError() since winsock recommend it.3rd
point,even the zero value of Connect()'s return code doesn't
mean that there's no data sent.It may also mean that the
operation is blocked now but will be sent anyway(and you will
get WSAEWOULDBLOCK as the error code).

> 奇怪的是虽然Connect(....)有错误,但是它发送给Server的消息
> server可以收到!有谁知道这是什么原因吗?
> 谢谢了!

--
※ 来源: 中国科大BBS站 [bbs.ustc.edu.cn]

无怨无悔

unread,
Oct 26, 1999, 3:00:00 AM10/26/99
to
> [1;36m==> Baggio_Luo(罗.比亚吉奥) 说道: [37;40m [0m

> GetLastError() returns last Win32 API's error code,
> so you should immediately call it before another Win32 API
> is called.But here you called AfxMessageBox() and it internally
> call Win32 API:MessageBox(),so the error code you got was the
> result of AfxMessageBox(),not Connect().2nd point,I think you
> should call WSAGetLastError() since winsock recommend it.3rd
> point,even the zero value of Connect()'s return code doesn't
> mean that there's no data sent.It may also mean that the
> operation is blocked now but will be sent anyway(and you will
> get WSAEWOULDBLOCK as the error code).
>
>
You are great!Thank you!

Now I have corrected it by override OnConnect(...),
during OnConnect(...),nErrorCode==0,it shows that there is no error,
and after Connect(...) I called GetLastError(...) it showed
WSAEWOULDBLOCK error, which is no problem.


to the first point you said,I have a word to say:
the GetLastError(...) I called is the member function of
class CAsyncSocket,will it return the result of AfxMessageBox(..)?

I am a newer,Thank you for your help!

--
※ 来源: 中国科大BBS站 [bbs.ustc.edu.cn]

0 new messages