Click here to Skip to main content
15,911,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i have write in vb.net server and client.i add on function for send and receive file and work fine,but when the file to trasfer are > 50kb code not work.Why?

receive
VB
Dim x As Integer
      x = ListView1.FocusedItem.Index
      Dim bytesToRead(cliente(x).ReceiveBufferSize) As Byte
      '---read incoming stream
      Dim numBytesRead As Integer = flusso(x).Read(bytesToRead,
                              0, CInt(cliente(x).ReceiveBufferSize))
      '---write the bytes to file

      Const FILE_NAME = "C:\Users\Sinestic\Desktop\11.jpg"
      Dim fs As System.IO.FileStream
      fs = New FileStream(FILE_NAME, FileMode.CreateNew,
                          FileAccess.Write)
      fs.Write(bytesToRead, 0, numBytesRead)
      fs.Close()


Sender

VB
Const FILE_NAME = "C:\Users\Sinestic\Desktop\10.jpg"
           Dim NWStream As NetworkStream = cliente.GetStream
           Dim bytesToSend(cliente.ReceiveBufferSize) As Byte
           Dim fs As FileStream
           fs = New FileStream(FILE_NAME, FileMode.Open,
                           FileAccess.Read)
           Dim numBytesRead As Integer = fs.Read(bytesToSend,
                           0, bytesToSend.Length)
           '---send the text
           Dim bf As New BinaryFormatter

           NWStream.Write(bytesToSend, 0, numBytesRead)
           TextBox5.Text = ""


What I have tried:

i try whit small file but i need trasfer large file
Posted
Updated 10-Jan-18 20:27pm

1 solution

Private Sub btnSend_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnSend.Click
Dim filebuffer As Byte()
Dim fileStream As Stream
fileStream = File.OpenRead(tbFilename.Text)
' Alocate memory space for the file
ReDim filebuffer(fileStream.Length)
fileStream.Read(filebuffer, 0, fileStream.Length)
' Open a TCP/IP Connection and send the data
Dim clientSocket As New TcpClient(tbServer.Text, 8080)
Dim networkStream As NetworkStream
networkStream = clientSocket.GetStream()
networkStream.Write(filebuffer, 0, fileStream.Length)
end sub

Read more at http://technotif.com/creating-simple-tcpip-server-client-transfer-data-using-c-vb-net/#83yQ1VtgVbgBmvYE.99
 
Share this answer
 
Comments
ebniebfiuyh 12-Jan-18 16:40pm    
Not work

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900