Announcement

Collapse
No announcement yet.

TCP NOTIFY & RECV

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • TCP NOTIFY & RECV

    I am dropping characters in this causing a messup in the
    received items. This is ported from VB where the recvdata comes in
    at a winsock1_DataArrival with the number of bytes received.
    I use TCP NOTIFY when characters are received, but have to call
    the receive and guess at the number of bytes until they are returned
    but I think I am getting another Notify message while I am working
    on the current string. By running my snippet, you will see, following
    the sort, how some names are messed up. Sure wish PB had
    a way to tell you how many bytes were received when notify hits you.

    Code:
    Compile Exe
    
    #Include "Win32api.inc"
    #Include "tcp32.inc" 'from samples\tcp
    Global f As Long
    %gotstuffmsg = 9172
    Global hdlg  As Long
    Global CommandString As String
    Global listitems() As String
    Global HoldOverData As String
    Global ApproxHeader As String
    Global startmsg As String
    Global stopmsg As String
    Global currentMsg As String
    Global subjectLine As String
    Global Nextrec As String
    
    
    Declare Function tryit() As Long
    
    Function PbMain()
        tryit
    End Function
    
    CallBack Function ok()
        Dim f As Long
        f = FreeFile
        Tcp Open Port 119 At "news.epix.net" As f TimeOut 3000
        Control Set Text hdlg, 104,"Connected"
        Tcp Notify f,Recv To hdlg As %GotStuffMsg
        commandstring = "LIST"
        Tcp Send f, CommandString & $CrLf
    End Function
    
    CallBack Function stopit()
         Beep:Sleep 2000:Beep
        Dialog End hdlg
    End Function
    
    CallBack Function dlgproc()
    Dim z As String ,y As String
    Dim fe As Long, crlf As Long,bytestotal As Long , HoldPos As Long
    'Dim holdoverdata As String <<< this was the error. Had to be static or global
    Static putlist As String
    Static hmm As Long
    Static InHere As Long
    Static x As Long
    Static beenHere As Long
    Dim wrap As String, recvData As String,rd As String
    wrap = Chr$(13,10)
        Select Case CbMsg
            Case %gotStuffMsg
                On Error GoTo dlgerr
                'recvdata = ""
                'tcp line input f, recvdata
                Do
                    Tcp Recv f,64780,rd
                    #Debug Print rd
                    recvData = recvData + rd
                Loop While IsTrue Len(rd) And IsFalse Eof(f) And IsFalse Err
                If CommandString = "LIST" Then
                Incr x
    UseData:
                bytestotal = Len(recvData)
                If hmm = 0 Then
                    Control Set Text hdlg, 104, "+" & Str$(bytestotal) & Str$(x)
                    hmm = 1
                    Else
                    Control Set Text hdlg, 104, "X" & Str$(BytesTotal) & Str$(x)
                    hmm = 0
                End If
    
                fe = FreeFile
               ' Open "server.lst" For Output As fe
                'reps = ubound(listItems)  ' need count....., later trigger receive again until code is completed.
                'redim preserve ListItems(3000) want to know how many
                recvdata = holdoverdata +recvdata
                HoldOverData = ""
                crlf = 0
    
                Do While crlf < bytestotal
                    holdPos = InStr(1,recvData, wrap)
                    If HoldPos = 0 Then
                        HoldOverData = recvData
                        Exit Do
                    End If
                    If HoldPos > bytesTotal Then
                        Exit Do
                    End If
    
                    PutList = Mid$(recvData,1,HoldPos)
                'putlist = recvdata
                   crlf = HoldPos + crlf
                   recvData = Mid$(recvData, HoldPos + 2)
                    ReDim Preserve ListItems(UBound(listItems)+1)
                    listItems(UBound(ListItems))=PutList
                    ListBox Add hdlg, 101,Mid$(PutList, 1, InStr(1,PutList, " "))
    
                   If (Mid$((Right$(recvData,3)),1,1) = ".") And (Right$(recvData,1) = Chr$(10)) And _
                        (Mid$((Right$(recvData,4)),1,1)<>Chr$(34)) Then
                        commandString = "None"
                        recvdata = ""
                        Control Set Text hdlg, 104, "List Download"
                        Beep
                        Exit Do
                    End If
                   'Dialog DoEvents
                Loop
                ' more to do
          End If
    
      End Select
        If CbCtl = 103 Then
            Beep
            Tcp Close f
            Control Set Text hdlg, 104, "Disconnected"
            Dialog DoEvents
            Sleep 2000
            Dialog End hdlg
        End If
    exfunc:
    Exit Function
        dlgerr:
        $Debug Print "Error code " & Str$(Err)
        'sleep 10000
        If Err = 70 Then
            Resume UseData
            Else
        Resume ExFunc
        End If
    End Function
    
    CallBack Function SortIt()
        Array Sort listitems()
        ListBox Reset hdlg,101
        Dim i As Long, s As String
        For i = LBound(ListItems) To UBound(ListItems)
            s = ListItems(i)
            ListBox Add  hdlg,101, Mid$(s, 1, InStr(1,s, " "))
        Next
        Control Set Text hdlg, 104, Str$(UBound(listitems)) & "Newsgroups found"
    End Function
    
    Function tryit() As Long
    
        Dim f As Long
    
        Global rmsg As Long
    
        Dialog New 0,"Tcp test" ,,,290,280 To hdlg
    
        Control Add ListBox, hdlg, 101, ListItems(), 1,1,280,220,%WS_VSCROLL Or %WS_HSCROLL
        Control Add Button, hdlg, 102, "Get Groups",100,250,40,14 Call Ok
        Control Add Button, hdlg, 103, "End", 150,250,40,14 'call stopit
        Control Add Label, hdlg, 104, "",1,263,100,14
        Control Add Button, hdlg, 105, "Sort em", 200,250,40,14 Call SortIt
        Dialog Show Modal hdlg, Call dlgproc
    End Function
    ' the above code works.. I don't need the sort routine (added
    the constant %LBS_SORT to the listbox. Also have to filter out
    the response messages that this picks up (200 = OK, 215 and 24hour support desk.


    ------------------


    [This message has been edited by Barry Erick (edited August 19, 2001).]
    Barry

  • #2
    Have it working. I had HoldOverData as global and also in the
    callback routine as local. Killing the local variable fixed the
    problem. I just have to filter out the OK msg "200" an the 215 message
    and the isps' "24 hour support" tag. Hmm.
    -Barry


    ------------------
    Barry

    Comment

    Working...
    X