Winsock 错误 40009 vb6

发布于 2024-12-03 12:14:59 字数 1062 浏览 2 评论 0原文

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

隔岸观火 2024-12-10 12:14:59

您没有列出所有代码,但我猜测变量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 the sendMsg "USER username" code early. You have to let the cinnection actually happen/complete before you can start writing to the socket.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文