Toon posts:

[VB.NET] TCPClient geopend in func.a, lijkt dicht in func.b

Pagina: 1
Acties:

Verwijderd

Topicstarter
Als ik een TCPClient open in functie a dan knalt mijn programma eruit bij functie b als ik er commando's naar wil zenden...

De connectie opzetten gaat prima, maar in de functie readmail knalt ie eruit bij de laatste regel die niet gecomment is (response = Send.....)

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Public Class pop3
    Dim tcpC As New TcpClient()

    Function SendCommand(ByRef netstream As NetworkStream, ByVal sToSend As String)
        Dim bData() As Byte = Encoding.ASCII.GetBytes(sToSend.ToCharArray)
        netstream.Write(bData, 0, bData.Length())
        Return GetResponse(netstream)
    End Function

    ' check if there is a response to get and return it
    Function GetResponse(ByRef netstream As NetworkStream)
        Dim bytes(tcpC.ReceiveBufferSize) As Byte
        Dim ret As Integer = netstream.Read(bytes, 0, bytes.Length)
        ' Returns the data received 
        Dim returndata As String = Encoding.ASCII.GetString(bytes)
        Return returndata
    End Function


    Function Connect(ByVal host As String, ByVal user As String, ByVal pass As String) As String
        Dim response As String
        Dim netstream As NetworkStream
        Try
            tcpC.Connect(host, 110)
        Catch ex As Exception
            response = ex.Message
            Return response
            Exit Function
        End Try
        netstream = tcpC.GetStream()
        response = GetResponse(netstream)
        response = SendCommand(netstream, "user " & user & vbCrLf)
        response = SendCommand(netstream, "pass " & pass & vbCrLf)
        Return response
    End Function

    Function Disconnect() As String
        Dim response As String
        Dim netstream As NetworkStream
        Dim thisResponse As String
        thisResponse = SendCommand(netstream, "QUIT" & vbCrLf)
        tcpC.Close()
    End Function

    Function ReadMail() As String
        Dim netstream As NetworkStream
        Dim response As String

        netstream = tcpC.GetStream()
        response = SendCommand(netstream, "stat" & vbCrLf)
        'Dim tmpArray() As String
        'tmpArray = Split(response, " ")
        'Dim thisMess As Integer
        'Dim numMess As String = tmpArray(1)
        'response = ""
        'If CInt(numMess) > 0 Then
        'numMess has the total nummber of message waiting for us on the server
        'For thisMess = 1 To CInt(numMess)
        'response += (SendCommand(netstream, "retr " & thisMess & vbCrLf))
        'Next
        'Else
        'response = "No messages"
        'End If
        Return response
    End Function
End Class

  • whoami
  • Registratie: December 2000
  • Laatst online: 24-08 16:37
Knalt ie eruit: welke error krijg je?
Heb je al eens gedebugged?

https://fgheysels.github.io/


  • Janoz
  • Registratie: Oktober 2000
  • Laatst online: 23-08 10:39

Janoz

Moderator Devschuur®

!litemod

hmm.. nee, probleem zal wel ergens anders liggen


Wel ff gekeken of het inloggen is gelukt? Waneer dat fout gaat kan het best zijn dat de verbinding door de server wordt gesloten.

[ Voor 80% gewijzigd door Janoz op 20-01-2003 16:13 ]

Ken Thompson's famous line from V6 UNIX is equaly applicable to this post:
'You are not expected to understand this'


Verwijderd

Topicstarter
inloggen gaat prima... debuggen levert op dat ie er uit knal op de regel netstream.Write(bData, 0, bData.Length()) door het aanroepen van :
response = SendCommand(netstream, "stat" & vbCrLf)

de foutmelding is dat de tcpclient open moet zijn.....

  • mulder
  • Registratie: Augustus 2001
  • Laatst online: 24-08 15:34

mulder

ik spuug op het trottoir

Ik zie je nergens Connect aanroepen.

oogjes open, snaveltjes dicht


  • whoami
  • Registratie: December 2000
  • Laatst online: 24-08 16:37
Verwijderd schreef op 20 January 2003 @ 17:53:
inloggen gaat prima... debuggen levert op dat ie er uit knal op de regel netstream.Write(bData, 0, bData.Length()) door het aanroepen van :
response = SendCommand(netstream, "stat" & vbCrLf)

de foutmelding is dat de tcpclient open moet zijn.....
Tja, dan zal je tcpclient niet open zijn. Gewoon ff checken of ie wel connected is voor je hem gebruikt, en als ie niet connected/open is, openen.

https://fgheysels.github.io/


Verwijderd

Topicstarter
whoami schreef op 20 januari 2003 @ 19:14:
[...]


Tja, dan zal je tcpclient niet open zijn. Gewoon ff checken of ie wel connected is voor je hem gebruikt, en als ie niet connected/open is, openen.
Ja die is dus open anders kan ik niet inloggen...............

Verwijderd

Check anders met een boolean of met een watch in de debugger net voordat je deze code uitvoert of de connection nog open is.

Verwijderd

Topicstarter
Don Facundo schreef op 20 January 2003 @ 18:13:
Ik zie je nergens Connect aanroepen.
Uhm is een klasse.....
Pagina: 1