Solved

# Sending jpg files client to server with Stream

Posted on 2008-02-01
Medium Priority
1,050 Views
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"

ReDim fileBuffer(fileStream.Length) ' set size of file
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.

Dim handlerSocket As Socket
handlerSocket = alSockets(alSockets.Count - 1)
Dim networkStream As NetworkStream = New NetworkStream(handlerSocket)
Dim blockSize As Int16 = 1024
Dim dataByte(blockSize) As Byte
SyncLock Me
Dim fileStream As Stream
fileStream = File.OpenWrite("C:\copiedtext.txt")
While (True)
Exit While
End If
fileStream.Write(dataByte, 0, dataByte.Length)
End While
fileStream.Close()
End SyncLock
handlerSocket = Nothing
End Sub

0
Question by:TDC_LuCiFeR
• 2
• 2

LVL 3

Author Comment

ID: 20802779
I need a solution fast as possible please!
ill give 500 more points!!!!
0

LVL 12

Accepted Solution

vb_jonas earned 2000 total points
ID: 20804804
Hi!
Change
fileStream.Write(dataByte, 0, dataByte.Length)
to

because the last read might not be 1024 bytes.
0

LVL 3

Author Closing Comment

ID: 31427296
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

LVL 12

Expert Comment

ID: 20805032
:-)
0

## Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.