Results 1 to 8 of 8

Thread: What is the best way of telling when a message starts/ends with winsock?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269

    What is the best way of telling when a message starts/ends with winsock?

    Currently im doing this..
    vb Code:
    1. sckAccept(index).GetData data
    2. data = addendum & data
    3.  
    4. lines = FindBetween2(data, "<My_Start_String>", "<My_End_String>")
    5. For x = 0 To UBound(lines) - 1
    6. data = Replace$(data, "<My_Start_String>" & lines(x) & "<My_End_String>", "")
    7. debug.print "MESSAGE RECEIVED: " & lines(x)
    8. next
    9.  
    10. addendum = data

    But surely there is a better way out there.. (ps: findbetween2 returns the string data between 2 strings.. in case of multiple matches it returns an array)

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269

    Re: What is the best way of telling when a message starts/ends with winsock?

    How does this look? Can it be made faster?

    vb Code:
    1. Dim endPoint As Long
    2. Const endString As String = "<My_End_String>"
    3.  
    4. Winsock.GetData Data
    5. Data = addendum & Data
    6.  
    7. Do
    8.     endPoint = InStr(Data, endString)
    9.     If endPoint > 0 Then
    10.         Debug.Print "message: " & Left(Data, endPoint - 1)
    11.         Data = Right(Data, Len(Data) - endPoint - Len(endString) + 1)
    12.     Else
    13.         Exit Do
    14.     End If
    15. Loop
    16.  
    17. addendum = Data

  3. #3
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: What is the best way of telling when a message starts/ends with winsock?

    The best way is to not use a string but one byte to start and one byte to end (STX and ETX). These are standard string communications protocols that you should look into.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269

    Re: What is the best way of telling when a message starts/ends with winsock?

    Quote Originally Posted by randem
    The best way is to not use a string but one byte to start and one byte to end (STX and ETX). These are standard string communications protocols that you should look into.
    this would be tough when sending binary data..

  5. #5
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: What is the best way of telling when a message starts/ends with winsock?

    Just send a header data where you specify the data length, see this thread for an example:
    http://www.vbforums.com/showthread.php?t=377648

  6. #6
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: What is the best way of telling when a message starts/ends with winsock?

    Yes, it would be tough but you stated you are sending string data not binary data...

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269

    Re: What is the best way of telling when a message starts/ends with winsock?

    yes but theres crazy characters in the string

  8. #8
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: What is the best way of telling when a message starts/ends with winsock?

    Then it's not a string, it's binary data...

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