Women in Technology

Hear us Roar

  Using Network Streams
Subject:   Large Files
Date:   2004-09-27 05:02:43
From:   Sefai
Your code does not work for files larger than 8192 bytes (default tcpclient send buffer size)

Reform your article so that it includes a working sample of files larger than 8k.

Full Threads Oldest First

Showing messages 1 through 1 of 1.

  • Re:Large Files
    2006-10-26 11:31:32  vaibe [View]

    hello there...
    just combine few concepts of network streams and you will be able to send larger files also(like .bmp,.jpeg etc..)
    server(receiving only)
    Const portNo As Integer = 500
    Const BUFFER_SIZE As Integer = 10
    Dim localAdd As System.Net.IPAddress = IPAddress.Parse("")
    Dim listener As New TcpListener(localAdd, portNo)
    Dim tcpClient As TcpClient = listener.AcceptTcpClient()
    Dim NWStream As NetworkStream = tcpClient.GetStream
    Dim bytesToRead(tcpClient.ReceiveBufferSize) As Byte
    Dim numBytesRead, j As Integer
    '---read incoming stream and writing the bytes to file
    Const FILE_NAME = "d:\image_copy.bmp"
    Dim fs As System.IO.FileStream
    fs = New FileStream(FILE_NAME, FileMode.CreateNew, FileAccess.Write)
    numBytesRead = NWStream.Read(bytesToRead, 0, BUFFER_SIZE)
    fs.Write(bytesToRead, 0, numBytesRead)
    Loop Until Not NWStream.DataAvailable

    client(sending a .bmp file)

    Const portNo = 500
    Const FILE_NAME = "d:\image.bmp"
    Dim tcpClient As New System.Net.Sockets.TcpClient
    tcpClient.Connect("", portNo)
    Dim NWStream As NetworkStream = tcpClient.GetStream
    Dim fs As FileStream
    Dim br As BinaryReader
    Dim numBytesRead As Integer
    fs = New FileStream(FILE_NAME, FileMode.Open, FileAccess.Read)
    br = New BinaryReader(fs)
    Dim bytesToSend(br.BaseStream.Length) As Byte
    numBytesRead = fs.Read(bytesToSend, 0, bytesToSend.Length)
    NWStream.Write(bytesToSend, 0, numBytesRead)
    hope it will help you :)