Hi All,

I have decided to try and learn about the programming side of TCP connections (well more try and get it working).

Im trying to send an image over the connection using network stream, it doesn't seem to be working as the receiver just freezes and end of story.

the image is made from a videosourceplayer which is a aForge.Net control that lets you hook a webcam to it, so basically the image is a webcam snap shot (if there is a way to send the output of the cam straight down the connection ill gladly take that). I have noticed there is a Image.FromStream which seems handy but is there maybe something like Image.ToStream???

My code so far (ps i have got text to send but i wish to have image).
Code:
Imports System.Net.Sockets
Imports System.IO
Imports AForge.Video.DirectShow

Public Class Form1
    Dim l As New TcpListener(3000)
    Dim c As TcpClient
    Dim Messages As String = ""
    Dim VideoCaptureSource As VideoCaptureDevice
    Dim VideoDevices As New FilterInfoCollection(FilterCategory.VideoInputDevice)


    Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
'stop webcam,timer and listener
        VideoSourcePlayer1.SignalToStop()
        VideoSourcePlayer1.WaitForStop()
        Timer1.Stop()
        l.Stop()
    End Sub
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'add ips, start listener, start timer
        ComboBox1.Items.Add("192.168.x.x")
        ComboBox1.Items.Add("192.168.x.x")
        l.Start()
        Timer1.Start()
'see if we have a webcam
        If VideoDevices.Count = 0 Then
        Else
'setup webcam and send video to videosourceplayer1
            Dim VideoCaptureSource2 As New VideoCaptureDevice
            VideoCaptureSource2 = New VideoCaptureDevice(VideoDevices(1).MonikerString)
            VideoSourcePlayer1.VideoSource = VideoCaptureSource2
            VideoSourcePlayer1.Start()
        End If

    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Try
'lets send something to ip in combobox
            c = New TcpClient(ComboBox1.Text, 3000)
            Dim ms = New MemoryStream()
            Dim uu As Image
            uu = VideoSourcePlayer1.GetCurrentVideoFrame
'save image into memorystream
            uu.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
'put memorystream into byte array
            Dim bytes = ms.ToArray()
'make network stream
            Dim ii As NetworkStream = c.GetStream
'write the byte array
            ii.Write(bytes, 0, bytes.Length)
            ii.Flush()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        Try
'setup listening
            If l.Pending = True Then
                c = l.AcceptTcpClient()
'set network stream
                Dim nn As NetworkStream = c.GetStream()
'make new image
                Dim h As Image
'create image from stream
                h = Image.FromStream(nn)
'set picture=stream
                PictureBox1.Image = h

            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class