Vb.net Invio immagine tramite Tcp
Riscrivo questo post dopo aver lavorato per due mesi ma proprio non riesco a risolvere
Non riesco a risolvere questo problema,vi spiego come funziona speriamo mi potete aiutare,tramite tcp invio un ommagine che catturo dal destop ogni 100ms.
Con sendimage e con ReceiveImage la ricevo.forse il problema e che la spedisco troppo grossa!!!
Come posso fare a per spedirla a blocchi in modo che la conessione non ne soffra o in qualche altro modo,mi potete aiutare.
Com'è funziona ma se supero 8000 byte mi genera un Exception!!
Private Sub sendimage()
Try
Dim ms As MemoryStream = New MemoryStream()
Dim img As Image = PictureBox1.Image
img.Save(ms, ImageFormat.Jpeg)
TextBox1.Text = ms.Length
Dim arrImage() As Byte
arrImage = (ms.GetBuffer())
ms.Close()
ms.Flush()
Dim myns As NetworkStream = Client.GetStream
Dim mysw As BinaryWriter = New BinaryWriter(myns)
mysw.Write(arrImage, 0, arrImage.Length)
mysw.Flush()
myns.Flush()
Catch ex As InvalidOperationException
Console.WriteLine(ex.ToString)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
----------------------------------------------------------------
Public Function ReceiveImage() As Boolean
Try
Dim bytesRead As Integer
Dim s As New MemoryStream()
Dim nws As NetworkStream
SyncLock client.GetStream
nws = client.GetStream
bytesRead = nws.Read(data, 0, client.ReceiveBufferSize)
Dim mysw As BinaryWriter = New BinaryWriter(s)
mysw.Write(data, 0, bytesRead)
PictureBox1.Image = Image.FromStream(s)
s.Close()
s.Flush()
nws.Flush()
End SyncLock
Catch ex As InvalidOperationException
MsgBox(ex.ToString)
Catch ex As Exception
MsgBox(ex.ToString)
Return False
End Try
Return True
End Function
Grazie!!