Sending jpg files client to server with Stream

Ok its a simple question im sure for someone but i have not used much .net and just got back into programming.  I have a simple client to server program made up and am able to send a text file across easy.  Im wondering what to change in my code to send a jpeg file.

Iv tried it using just this code and the jpeg is distorted although u can see some of the screen.
Im just looking for a quick manipulation of my code here sort this,  I dont want to have to change much if possible.    I am thinking its probably a binary read i need or  a full byte for byte read.

Im using Visual Studio 2005.


'Here is the Client Code
 
Private Sub SendInfoFile()
        Dim fileBuffer As Byte()
        Dim fileStream As Stream
        Dim fback As String
        fback = "C:\text1.txt"
 
        fileStream = File.OpenRead(fback) 'open file to read
        ReDim fileBuffer(fileStream.Length) ' set size of file
        fileStream.Read(fileBuffer, 0, fileStream.Length) ' read the file in
        Dim clientSocket As New TcpClient(IPAddy, 667) 'send back on port 667 to Ip address of client in Global IPaddy
        Dim netWorkStream As NetworkStream
        netWorkStream = clientSocket.GetStream()
        netWorkStream.Write(fileBuffer, 0, fileStream.Length)
        netWorkStream.Close()
    End Sub
 
 
'And here is the code for the Server to Catch and write the file.
 
Public Sub handlerThread()
        Dim handlerSocket As Socket
        handlerSocket = alSockets(alSockets.Count - 1)
        Dim networkStream As NetworkStream = New NetworkStream(handlerSocket)
        Dim blockSize As Int16 = 1024
        Dim thisRead As Int16
        Dim dataByte(blockSize) As Byte
        SyncLock Me
            Dim fileStream As Stream
            fileStream = File.OpenWrite("C:\copiedtext.txt")
            While (True)
                thisRead = networkStream.Read(dataByte, 0, blockSize)
                If thisRead = 0 Then
                    Exit While
                End If
                fileStream.Write(dataByte, 0, dataByte.Length)
            End While
            fileStream.Close()
        End SyncLock
        lbxConnections.Items.Add("File Written")
        handlerSocket = Nothing
    End Sub

Open in new window

LVL 3
TDC_LuCiFeRAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TDC_LuCiFeRAuthor Commented:
I need a solution fast as possible please!
ill give 500 more points!!!!
0
vb_jonasCommented:
Hi!
Change
                fileStream.Write(dataByte, 0, dataByte.Length)
to
                fileStream.Write(dataByte, 0, thisRead)

because the last read might not be 1024 bytes.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TDC_LuCiFeRAuthor Commented:
Thank you very much, i see what you mean exactly.  Iv been tormenting myself with it,  ty very much,  my .jps were coming through but a bit distorted!  Here is points also if u leave a comment in the section.

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_23130764.html
0
vb_jonasCommented:
:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.