Winsock错误40009 vb6

时间:2011-09-07 13:12:57

标签: vb6 winsock

 Winsock1.Connect "mail.website.com", 110

 Do Until received: DoEvents: Loop

 If sckError Then MsgBox "An error occured trying to connect to server": Exit Sub

 sendMsg "USER username"  ' Send UserName
 If sckError Then MsgBox "Error with username": Exit Sub

 sendMsg "PASS password"   ' Send Password
 If sckError Then MsgBox "Error with password": Exit Sub


' Get Number of Messages and total size in bytes
 sendMsg "STAT"
 x = InStr(Message$, " "): b = InStrRev(Message$, " ")
 messages = Val(Mid$(Message$, x + 1, b - x))
 Size = Val(Mid$(Message$, b + 1))
 If messages = "0" Then
 MsgBox "no new messages"
 GoTo l
 End If

 For a = 1 To messages
    Winsock1.Tag = "RETR"
    Open "C:\Windows\Temp\eMail-" & a & ".eml" For Binary Access Write As #1

    sendMsg "RETR " & a
    List1.AddItem "eMail-" & a & ".eml"
  Next

  Winsock1.Tag = ""

 Next
l:
Winsock.Close

当我第一次运行它时,它完美运行,但是当我尝试再次运行它而没有关闭应用程序时,它给了我40009错误。我想我试图在连接之前发送数据。有没有办法看看winsock是否连接?像

这样的东西

如果winsock1.state = true则...

1 个答案:

答案 0 :(得分:0)

您没有列出所有代码,但我猜测变量received未重置,导致您提前直接转到sendMsg "USER username"代码。在开始写入套接字之前,你必须让cinnection真正发生/完成。

相关问题