Results 1 to 3 of 3

Thread: send binary through Winsock

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Posts
    251

    send binary through Winsock

    hi all im trying to convert a text value in to ByteArray
    hold 160 bit in a buffer send the buffer every 20 ms through a winsock using UDP .


    any help suggestions will be appreciated alot



    Here's what I have so far


    Private Sub Command1_Click()
    Dim Ff as Integer,
    Dim By As Byte
    Ff = FreeFile
    Open "C:\test.txt" For Binary as #Ff
    Get #Ff, , By
    Close #Ff
    Winsock1.SendData By
    End Sub

    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim By As Byte
    Winsock1.GetData By
    End Sub
    Last edited by bordino; Jun 15th, 2011 at 09:34 AM.

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: send binary through Winsock

    You need to read 20 Bytes rather than just 1
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    Dim Ff As Integer
    Dim By(19) As Byte
    Ff = FreeFile
    Open "C:\test.txt" For Binary As #Ff
    Get #Ff, , By
    Close #Ff
    Winsock1.SendData By
    End Sub
    
    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim By() As Byte
    Winsock1.GetData By
    End Sub

  3. #3
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: send binary through Winsock

    You still have a serious bug there, as pointed out in the ancient article The Lame List:
    Assuming stream sockets maintain message frame boundaries. Mind bogglingly lame.

    Reason: Stream sockets (TCP) are called stream sockets, because they provide data streams (duh). As such, the largest message size an application can ever depend on is one-byte in length. No more, no less. This means that with any call to send() or recv(), the Winsock implementation may transfer any number of bytes less than the buffer length specified.
    This means your GetData call might easily return 1 byte or some other length short of what the naive code expects... or more if the other end did 2 or more SendData calls.

    All progams need to buffer their received data and deblock messages based on application framing criteria, such as message length, delimiters, etc.
    Last edited by dilettante; Jun 16th, 2011 at 07:03 AM.

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