Master Zero
Well-known member
- Joined
- Sep 10, 2005
- Messages
- 51
- Programming Experience
- Beginner
Good morning all!
I’ am having trouble getting this code to work properly. This is the client code:
It works, but it is only able to transfer files less then 1 mb.
How can I get this code to be able to send lager files?
Thank in advances
Side note: This code came from another project which you can find here: http://pscode.com/vb/scripts/ShowCode.asp?txtCodeId=2171&lngWId=10&txtForceRefresh=910200510483466942
I’ am having trouble getting this code to work properly. This is the client code:
VB.NET:
Dim IP As String = InputBox("Enter the IP address or hostname of you traget!", _
"IP Address", "127.0.0.1")
Client = New TcpClient
Client.Connect(IP, 1234)
Dim NWStream As NetworkStream = Client.GetStream
Dim bytesToSend(Client.SendBufferSize) As Byte
Dim FI As New FileInfo(OpenFileDialog1.FileName)
ProgressBar1.Maximum = FI.Length
Dim FileSTR As New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
Dim FileReader As New BinaryReader(FileSTR)
Dim numBytesRead As Integer
Dim Ipos As Integer
Do Until Ipos >= FI.Length
numBytesRead = FileSTR.Read(bytesToSend, 0, bytesToSend.Length)
NWStream.Write(bytesToSend, 0, numBytesRead)
Ipos = Ipos + numBytesRead
ProgressBar1.Value += numBytesRead
ProgressBar1.Update()
NWStream.Flush()
Loop
NWStream.Flush()
FileSTR.Close()
FileReader.Close()
This is the server code:
Try
Dim Client As TcpClient = TCP.AcceptTcpClient()
Dim NWStream As NetworkStream = client.GetStream
Dim bytesToRead(client.ReceiveBufferSize) As Byte
Dim numBytesRead As Integer '= NWStream.Read(bytesToRead, 0, CInt(client.ReceiveBufferSize))
Dim BUFFER_SIZE As Integer = client.ReceiveBufferSize
Dim FileSTR As New FileStream(TextBox1.Text, FileMode.CreateNew, FileAccess.Write)
Do
numBytesRead = 0
numBytesRead = NWStream.Read(bytesToRead, 0, BUFFER_SIZE)
FileSTR.Write(bytesToRead, 0, numBytesRead)
StatusBarPanel1.Text = "Downloaded: " & numBytesRead & " KB."
'The NWStream.DataAvailable always returned false in-between packets so double check by using "And numBytesRead = 0"
Loop Until NWStream.DataAvailable = False 'And numBytesRead = 0
FileSTR.Close()
NWStream.Close()
Client.Close()
MsgBox("All done!")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
It works, but it is only able to transfer files less then 1 mb.
How can I get this code to be able to send lager files?
Thank in advances
Side note: This code came from another project which you can find here: http://pscode.com/vb/scripts/ShowCode.asp?txtCodeId=2171&lngWId=10&txtForceRefresh=910200510483466942
Last edited: