|
-
Oct 21st, 2022, 06:09 AM
#1
Junior Member
Re: [VB2008/.NET 3.5] Asynchronous TcpListener & TcpClient
 Originally Posted by jmcilhinney
@MHutcheon, this is the important part:
vb.net Code:
'Convert the text message to binary data.
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...
-
Oct 21st, 2022, 09:21 AM
#2
Re: [VB2008/.NET 3.5] Asynchronous TcpListener & TcpClient
 Originally Posted by MHutcheon
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.
-
Oct 21st, 2022, 03:01 PM
#3
Junior Member
Re: [VB2008/.NET 3.5] Asynchronous TcpListener & TcpClient
 Originally Posted by jmcilhinney
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|