首页
社区
课程
招聘
winsock2编程
发表于: 2006-3-9 10:38 6033

winsock2编程

2006-3-9 10:38
6033
invoke WSAEventSelect,sockid,@Event,FD_CONNECT or FD_CLOSE
  invoke connect,sockid,addr @addr,sizeof @addr
  .while TRUE
    invoke WSAWaitForMultipleEvents,1,addr @Event,FALSE,WSA_INFINITE,FALSE
        invoke WSAResetEvent,@Event
        invoke WSAEnumNetworkEvents,sockid,@Event,addr @NetEvent
       
        .if @NetEvent.lNetworkEvents == FD_CONNECT
          .if @NetEvent.iErrorCode[FD_CONNECT_BIT] != 0
            invoke MessageBox,0,SADD("失败"),0,0
            continue;
          .endif
          
          invoke MessageBox,0,SADD("成功"),0,0
               
        .elseif @NetEvent.lNetworkEvents & FD_CLOSE
          invoke MessageBox,0,SADD("关闭"),0,0
        .endw

为什么连接成功也会进入
invoke MessageBox,0,SADD("失败"),0,0这里?

而且WSAGetLasrError发现错误是10035
为什么已经WSAWaitForMultipleEvents了还会出现“无法立即完成一个非阻挡性套接字操作。 ”

这一段代码在VC中是正常的~

[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!

收藏
免费 0
支持
分享
最新回复 (2)
雪    币: 235
活跃值: (100)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
2
.386
.model flat,stdcall
option casemap:none

include windows.inc
include user32.inc
include kernel32.inc
include ws2_32.inc

includelib user32.lib
includelib kernel32.lib
includelib ws2_32.lib

include D:\WinAsm\masm32\macros\macros.asm

main proto

.code
start:
invoke main
invoke ExitProcess,0

main proc
        LOCAL @wsaData:WSADATA
        LOCAL @sockid:SOCKET
        LOCAL @addr:sockaddr_in
        LOCAL @Event:HANDLE
        LOCAL EventWork:WSANETWORKEVENTS
       
        LOCAL buf[100]:BYTE
       
        invoke WSAStartup,202h,addr @wsaData
       
        mov @sockid,FUNC(socket,AF_INET,SOCK_STREAM,0)
       
        mov @addr.sin_family,AF_INET
        mov @addr.sin_addr.S_un.S_addr,FUNC(inet_addr,SADD("127.0.0.1"))
        invoke htons,90
        mov @addr.sin_port,ax
       
        invoke bind,@sockid,addr @addr,sizeof @addr
       
        invoke WSACreateEvent
        mov @Event,eax
        invoke WSAEventSelect,@sockid,@Event,FD_CONNECT or FD_CLOSE
        invoke connect,@sockid,addr @addr,sizeof @addr
       
        ;invoke wsprintf,addr buf,SADD("%d"),FUNC(WSAGetLastError)
        ;invoke MessageBox,0,addr buf,0,0
       
        .while TRUE
                invoke WSAWaitForMultipleEvents,1,addr @Event,FALSE,INFINITE,FALSE
                invoke WSAResetEvent,@Event
                invoke WSAEnumNetworkEvents,@sockid,@Event,addr EventWork
               
                .if EventWork.lNetworkEvents == FD_CONNECT
                        .if EventWork.iErrorCode[FD_CONNECT_BIT] != 0
                                invoke MessageBox,0,SADD("连接失败"),0,0
                                .break
                        .endif
                       
                        invoke MessageBox,0,SADD("连接成功"),0,0
                .elseif EventWork.lNetworkEvents == FD_CLOSE
                        invoke MessageBox,0,SADD("连接关闭"),0,0
                .endif
        .endw
       
        invoke WSACleanup
        Ret
main EndP

end start

完整代码~~

连接成功了,还是会进入invoke MessageBox,0,SADD("连接失败"),0,0

为什么????????????????????

实在不懂
2006-3-11 02:50
0
雪    币: 203
活跃值: (26)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
The iErrorCode array is used to contain any associated error codes with the array index corresponding to the position of event bits in lNetworkEvents. Identifiers such as FD_READ_BIT and FD_WRITE_BIT can be used to index the iErrorCode array. Note that only those elements of the iErrorCode array are set that correspond to the bits set in lNetworkEvents parameter. Other parameters are not modified

看最后一句,呵呵,原因在此
2006-3-16 14:54
0
游客
登录 | 注册 方可回帖
返回
//