Results 1 to 2 of 2

Thread: [2008] Receiving Image - Sockets

  1. #1

    Thread Starter
    Addicted Member Dayjo's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    130

    [2008] Receiving Image - Sockets

    Hey, I'm trying to send an image over a connection using sockets. As far as I know I'm sending it correctly from the client:

    Code:
        Public Sub TransferData(ByVal FromStream As IO.Stream, ByVal BufferSize As Integer)
            Dim buffer(BufferSize - 1) As Byte
            Dim ToStream As IO.Stream = mobjClient.GetStream
            Do While True
                Dim bytesRead As Integer = FromStream.Read(buffer, 0, buffer.Length)
                If bytesRead = 0 Then Exit Do
                ToStream.Write(buffer, 0, bytesRead)
            Loop
    
        End Sub
    
    
    Dim spath As String = "c:\screen.gif"
    Dim sfilestrean As FileStream
    Dim sfilestream = New FileStream(spath, FileMode.Open, FileAccess.ReadWrite)
    
    TransferData(sfilestream, 1024)
    The server does receive the data. But I'm trying to figure out how to put it all back together on the other end.

    I send start and end messages like so: "Image" [image data] "End Image".

    In the server I have a sub that gets the data.. when receiving the message "Image" it sets a variable (receivingImage = True) and "End Image" sets it to False.

    So on this sub, if receivingImage = True I guess I need to put the received bytes into an array so I have:
    Code:
    Dim imagetmp(1024) As Byte
            If receivingScreen = True Then
                mobjClient.GetStream.Read(imagetmp, imagetmp.Count, CInt(mobjClient.ReceiveBufferSize))
            End If
    Which is probably massively incorrect. I've never done anything like this, so some help would be great

    Cheers

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Receiving Image - Sockets

    I would strongly advice you to create a separate TCP connection per file transfer. It makes everything so much easier, as you dont have to deal with all these message delimiters and boolean flags. This is the way numerous applications deal with this problem, such as applications that implement the FTP protocoll.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

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