Results 1 to 9 of 9

Thread: Winsock

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    367
    I am using a winsock control to make a telnet control.

    My problem is, i can not tell when data arrival has recieved all the data back, for it seems that TCP returns data in chunks. I wish there was a dataarrival complete, does anyone here know how to help me?

    Code:
        Dim i As Long
        Dim j As Integer
        Dim Wait As Double
        
        Do While Not SEND_COMPLETE
            DoEvents
        Loop
            
        ' Clear flag to indicate send is not complete
        SEND_COMPLETE = False
          
        i = VBControls.lstHostOutput.ListCount
        HOST_IMAGE_INCOMPLETE = True
        
        VBControls.tcpClient.SendData strString
        
        Wait = Now + SecondsToWait / (3600# * 24#)
        
        Do Until (SEND_COMPLETE) Or (Now > Wait)
            DoEvents
        Loop
        
        CommandError = False
        
        'If Now > Wait Then
        '    CommandError = True
        'End If
        HOST_IMAGE_INCOMPLETE = True
        
        Do While HOST_IMAGE_INCOMPLETE
            DoEvents
        Loop
        
        LineCount = VBControls.lstHostOutput.ListCount - i
        For j = 0 To LineCount - 1
            OutputLines(j + 1) = VBControls.lstHostOutput.List(i + j)
        Next j
    This works if I just one break point in, even if I just hit F5 and let my program continue simulation. It fills out my array nicely, but if I run with no break points all this finishes before say data_arrival has recieved the data back.

  2. #2
    Guest

    Talking

    I could be wrong, but I think this is it:

    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    If Winsock1.BytesReceived <> bytesTotal Then Exit Sub
    End Sub

    That way it won't execute your winsock1.getdata stuff unless it has received all the data.

  3. #3
    Addicted Member
    Join Date
    Apr 2000
    Posts
    215
    no I think the bytestotal is the size of chunk of data recieved,if you know the bytes size of the data you are sending, you could add all the bytestotal up until they reach that size?.

  4. #4
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    Your right. The bytestotal is the number of bytes you just received which if the data is large will be a "chunk" that matches your maximum packet size (ie 1024, 2048 etc)

    What you need to understand is this :

    What determines that I have ENDED one section of data and STARTED another section?

    If I was to write a Winsock application that talked to another one then there would be a character somewhere that said "End Transmission"

    If however data is "streamed" and is delivered in chunks then the "end" of my data would come when the number of bytes received is less than the total size of my maximum packet.

    Imagine this :

    Code:
    10000 bytes to send in total
    
    DataArrival occurs : bytestotal = 2048 (ie 7592 bytes left)
    DataArrival occurs : bytestotal = 2048 (ie 5904 bytes left)
    DataArrival occurs : bytestotal = 2048 (ie 3856 bytes left)
    DataArrival occurs : bytestotal = 2048 (ie 1808 bytes left)
    DataArrival occurs : bytestotal = 1808
    The first time I receive a number of bytes LESS than my maximum packet size I know it is the last of a particular CHAIN of data.

    There are 2 problems with this :

    1. What if I receive EXACTLY 2048 bytes?
    2. What if another CHAIN of data is appended to the first?

    The answer to that is you use a character to determine where the breaks are.

    So If you are saying you are using Winsock to read from a pre-existing and already functioning program then you need to read up on the protocol they are using to determine what they use to signify the end of a data chunk.

  5. #5
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    Winsock receives data in packets so there is no reliable way to know when data has finished or whether it has just stalled by a poor connection.

    For this reason Telnet usually writes to screen as data arrives in a stream.

    If you're going as far as vt-100 emulation then I beleive you have ctrl characters to work with so as to know the end of blocks etc.

    remember it's an interactive session, sometimes data flow doesn't end! the server app just keeps outputting till ctrl C is sent. If the user has to wait for a break in the flow before reading or being able to send text then it may just keep buffering!

    alternatively, buffer till the vbCr (many unix systems don't use dos vbCRLf

    Have you checked the RFCs?

    http://ata.cs.hun.edu.tr/turkce/dige...ml/RFC854.html

    The telnet command structure is explained here



    [Edited by Paul282 on 06-09-2000 at 07:39 AM]
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    367
    Yeah, I have read the the rfc's. So far I have fixed the problem with putting a call into the sleep api call. (What a pitiful hack). But for as to why this works is beyond me.

  7. #7
    New Member
    Join Date
    Jun 2002
    Location
    Brisbane, Australia
    Posts
    1
    Could you direct me to the relevant RFC's? What are the RFC's for VT100?

  8. #8
    Fanatic Member kevin_sauerwald's Avatar
    Join Date
    Feb 2002
    Location
    outside Philly
    Posts
    516

    Telnet Program

    Reading your guys chats...

    I need to write some code to attach to a Unix box...
    send a script..
    run it...

    I can use the ftp commands to send it .. but I need to run it..

    anyone got some base code to telnet over give username and password then be able to issue unix commands to run ??

    help !!

  9. #9
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180
    An app is sending data to you. Why don't you let it send a message containing the max. amount of data it's going to send first.
    So you receive a message containing something like:
    "Max:100292". Then you can just add the bytestotal every time some data comes in and this way see when you're finished.

    (or has it already been said )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width