Winsock 错误 40009 vb6
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 那么...
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
When i run this the first time it works perfectly, but when i try to run it a second time w/o closing the app, it gives me the 40009 error. I'm thinking im trying to send data before its connected. is there a way to see if winsock is connected? somthing like
if winsock1.state = true then...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有列出所有代码,但我猜测变量
received
未重置,导致您直接进入sendMsg“USER username”
尽早编码。在开始写入套接字之前,您必须让连接真正发生/完成。You didn't list all of the code, but I'm guessing that the variable
received
is not reset, causing you to fall through directly to thesendMsg "USER username"
code early. You have to let the cinnection actually happen/complete before you can start writing to the socket.