Results 1 to 40 of 273

Thread: [VB2008/.NET 3.5] Asynchronous TcpListener & TcpClient

Hybrid View

  1. #1
    Junior Member
    Join Date
    Oct 2022
    Location
    West Sussex
    Posts
    29

    Re: [VB2008/.NET 3.5] Asynchronous TcpListener & TcpClient

    Quote Originally Posted by jmcilhinney View Post
    @MHutcheon, this is the important part:
    vb.net Code:
    1. 'Convert the text message to binary data.
    2. Dim buffer As Byte() = Me.Encoding.GetBytes(message)
    That is converting the String to a Byte array. You need to accept an Image and convert that to a Byte array. The thread I was referring to that demonstrates that is here:

    https://www.vbforums.com/showthread....a-in-Databases

    Note that, as an Image may be fairly big, you might want to write it in chunks.
    Hi,

    My code is stopping at this point, saying:
    'Public Overrides Function GetBytes(s As String) As Byte()':
    Argument matching parameter 's' cannot convert from 'Byte()' to 'String'.
    and when I hover over message it is confirming for me message is a byte array - byte() - and has a length of 36167 bytes. If I read it correctly, the code is trying to convert my array back to a string? This is well beyond my level

    PS - apologies if I am straying off course here...

  2. #2

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [VB2008/.NET 3.5] Asynchronous TcpListener & TcpClient

    Quote Originally Posted by MHutcheon View Post
    when I hover over message it is confirming for me message is a byte array - byte() - and has a length of 36167 bytes. If I read it correctly, the code is trying to convert my array back to a string? This is well beyond my level
    The point of calling Encoding.GetBytes is to convert a String to a Byte array. You're not using Strings so you don't use that method at all, especially not to pass a Byte array in. As you can see from then existing code, you get the Byte array from the original data and then you write it to the stream. Your original data is an Image. Get a Byte array from that and then write it to the stream.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Junior Member
    Join Date
    Oct 2022
    Location
    West Sussex
    Posts
    29

    Re: [VB2008/.NET 3.5] Asynchronous TcpListener & TcpClient

    Quote Originally Posted by jmcilhinney View Post
    The point of calling Encoding.GetBytes is to convert a String to a Byte array. You're not using Strings so you don't use that method at all, especially not to pass a Byte array in. As you can see from then existing code, you get the Byte array from the original data and then you write it to the stream. Your original data is an Image. Get a Byte array from that and then write it to the stream.
    I thought that was what I was trying to. Here is my code to generate the byte array:
    Code:
    picScreenCapture.Image = CropImage
    Dim ms As New MemoryStream
    CropImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
    
    Dim arrImage() As Byte
    arrImage = ms.GetBuffer
    
    For Each recipient In arListOfRecipients
        Dim arElements As String() = recipient.ToString.Split(New String() {":"}, StringSplitOptions.None)
        Dim tmpIP As String = arElements(0)
        Dim tmpPort As Integer = arElements(1)
                    
       IMGserver.Send(tmpIP, tmpPort, arrImage)
    Next
    but using this generates the error in post 271.

    I don't really understand how get the code to use the different instances of MessageServer.

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