Results 1 to 5 of 5

Thread: [RESOLVED] handling raw data after it reaches winsock

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2008
    Posts
    327

    Resolved [RESOLVED] handling raw data after it reaches winsock

    hi all,
    i have been stuck at it quite a while, i did make a post about it but it was lost so, i have made my own client/server which uses a certain asc char and length of the data in its tcp data.....the server sends tcp data which reaches the client winsock control and then process it...
    as i receive the data i split them up ...i have used chr(02) to mark the begining of my data and used the 9th byte to mark the length of the data
    after i receive my data ..i use this code to process them.
    Code:
     Dim sPackS As Integer
    Dim sPackE As Integer
    Dim i As Integer
    Dim j As Integer
    Dim sLast As Integer
    Dim sType As DataTypes
    Dim sData As String
    Dim sAllData As String
    Dim sLength As String
    For i = 1 To Len(iData) ' loop around each character
        If Mid(iData, i, 1) = "chr(02)" Then ' find the character char(02)
           sLength = Asc(Mid(iData, 9, 1)) ' find the length of the packet
            sPackS = i + 1 ' set the position of the packet 
            For j = sPackS To Len(iData)
                If (j = Len(iData)) And Mid(iData, j, 1) <> "chr(02)" Then
                    sPackE = Len(iData)
                    sAllData = Mid(iData, sPackS, sPackE)
                    sAllData = iData
                    If Len(sAllData) < 3 Then
                        sType = sAllData
                    Else
                        sType = Asc(Mid(sAllData, 2, 1))
                       sData = Mid(sAllData, 4, (Len(sAllData) - 3))
                    End If
                    Call Incoming_Data(sType, sData)
                    Exit Sub
                ElseIf Mid$(iData, sLength + 10, 1) = "chr(02)" Then ' find the end of the packet and process it 
                  sPackE = (sLength + 8)
                    sAllData = Mid(iData, sPackS, sPackE)
                     If Len(sAllData) < 3 Then
                      sType = sAllData
                    Else
                      sType = Asc(Mid(sAllData, 2, 1))
                        sData = Mid(sAllData, 4, (Len(sAllData) - 3))
                    End If
                      Call Incoming_Data(sType, sData)
                    Exit For
                
                End If
            Next j
        End If
    Next i
    End Sub
    to make the tcp data a little complicated i have used chr(02) in between my the tcp data that the server sends to the client
    this is a data that the server sends to the client
    Code:
    chr(02)ô.....Ochr(02)...pannam....
    'roompearls....hello this is a message....chr(02).........
    the above code of the client can handle if the data are less in number for example less than 10 or so...but if i send a lot of data at the same time let's say 100 then 5 or more data are cut off and only 95 are shown in the text box..although in the debug window all the data arrive..the reason for this is..the last data has to run through..
    Code:
      If (j = Len(iData)) And Mid(iData, j, 1) <> "chr(02)" Then
                    sPackE = Len(iData)
                    sAllData = Mid(iData, sPackS, sPackE)
                    sAllData = iData
                    If Len(sAllData) < 3 Then
                        sType = sAllData
                    Else
                        sType = Asc(Mid(sAllData, 2, 1))
                       sData = Mid(sAllData, 4, (Len(sAllData) - 3))
                    End If
                    Call Incoming_Data(sType, sData)
                    Exit Sub
    but it doesnot..rather runs through the latter part of the code and gives the out put..
    i am uploading my server /client which is quite simple..i hope some body can help me out with this..coz i am stuck with it real bad..
    Last edited by pannam; Aug 12th, 2008 at 08:36 AM.

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2008
    Posts
    327

    Re: handling raw data after it reaches winsock

    hey...somebody ..???? common guyz please take a look this shouldn't be difficult.. before this post gets trashed ..please

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: handling raw data after it reaches winsock

    i don't understand the question.

    it seems that you are sending message(s) from the server to the client. the message starts with 02 and has a length in the 9th byte. if the messages are 8 bytes long why send 02 and the length?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2008
    Posts
    327

    Re: handling raw data after it reaches winsock

    Quote Originally Posted by dbasnett
    i don't understand the question.

    it seems that you are sending message(s) from the server to the client. the message starts with 02 and has a length in the 9th byte. if the messages are 8 bytes long why send 02 and the length?
    02 is the start of my tcp data, all my data has 02 at its begining .
    the problem i face is 02 is present in between the tcp data for example "...02..........blah blah ...02 ....02 ... " and so. and i don't want to change the tcp data rather my code so, i can process the data . ..now, the reason i am using the length in the 9 th byte is because i count the number of bytes from there and add 9 which makes it one complete tcp data. this way even if i get lots of data in my winsock i can handle them by knowing the length of the data....my only problem is i cannot process the last data that arrives in my winsock because the last data has to run through

    Code:
      If (j = Len(iData)) And Mid(iData, j, 1) <> "chr(02)" Then 'this is the last data that is present in the winsock
                    sPackE = Len(iData)
                    sAllData = Mid(iData, sPackS, sPackE)
                    sAllData = iData
                    If Len(sAllData) < 3 Then
                        sType = sAllData
                    Else
                        sType = Asc(Mid(sAllData, 2, 1))
                       sData = Mid(sAllData, 4, (Len(sAllData) - 3))
                    End If
                    Call Incoming_Data(sType, sData)
                    Exit Sub
    which i fail to do..

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2008
    Posts
    327

    Re: handling raw data after it reaches winsock

    anywayz i got it right i changed
    Code:
    ElseIf Mid$(iData, sLength + 10, 1) = "chr(02)"
    to
    Code:
     ElseIf Mid$(idata, j, 1) = "chr(02)"Then
    this way the code finds out if there are any more chr(02) in the packet if there is then i have written code to find out if its the start of a packet or just a char in the packet..if its the start of a fresh data then it process it or else omits it and loops.

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