I want to sent picture with socket programming, from client to server.
client : get picture from OpenFileDialog, after get the picture , I send it to server.
server : after get the picture from client, the picture is saved in a destination folder.
I try my best, but all I can send is only 8kb picture.
if the picture larger than 8 kb, then at destination folder, only 8kb will be saved, and rest of the saved picture are blank...
here my current code:
Dim fileStream As FileStream = File.Open([filename], FileMode.Open, FileAccess.Read, FileShare.Read) Dim reader As BinaryReader = New BinaryReader(fileStream) Dim fileLength As Long = fileStream.Length Dim sendBytes(fileLength) As Byte reader.Read(sendBytes, 0, fileLength) serverStream.Write(sendBytes, 0, fileLength) fileStream.Close() reader.Close()
Dim bgStream As NetworkStream = clientSocket.GetStream() Dim bgbytes(100024) As Byte bgStream.Read(bgbytes, 0, CInt(clientSocket.ReceiveBufferSize)) Dim gmb As New FileStream([filename], FileMode.Create, FileAccess.Write, FileShare.Write) Dim fileLength As Long = bgbytes.Length Dim writer As BinaryWriter = New BinaryWriter(gmb) writer.Write(bgbytes) writer.Close() gmb.Close()