Hi guys. I have a problem.. i am trying to transfer files from one computer to an other(yes i did port forwarding)..the thing is that if i use 1024-1(buffer) and 1024-1(buffer) in both programs it will NOT transfer any file..it will just create a file with 0kb. size.. So if i use 128-1(buffer) in the program that i want to send file and 2-1(buffer) in receiver program it works ONLY FOR JPG!!! HOW CAN THIS HAPPEN? LOL... all other files are being created as 0kb and it will not transfer the file... any help please??? i have this code to the program that i want to send one file:
Imports System.Net.Sockets
Imports System.IO
Module gtsnfl
#Region "get file"
Public Sub getfile(ByVal path As String)
filePathst = path
Dim sendThread As New System.Threading.Thread(AddressOf sendSub)
sendThread.IsBackground = True
sendThread.Start()
End Sub
#Region "send"
Private filePathst As String
Delegate Sub nan()
Public Sub sendSub()
Dim clist As New TcpClient
clist.Connect(Form1.myip, 1301)
Try
Dim nstm As Stream = clist.GetStream()
Dim fstm As Stream = New FileStream(filePathst, FileMode.Open, FileAccess.Read)
Dim buffer(128 - 1) As Byte
Do While True
Dim bytesRead As Integer = fstm.Read(buffer, 0, buffer.Length)
If bytesRead = 0 Then Exit Do
nstm.Write(buffer, 0, bytesRead)
nstm.Flush()
Loop
clist.Close()
nstm.Close()
fstm.Close()
Catch ex As Exception
End Try
End Sub
#End Region
#End Region
End Module
and i also have this code in the program that will receive the file..
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ListenThreadtr As System.Threading.Thread = New System.Threading.Thread(AddressOf ListenSubFiles)
ListenThreadtr.IsBackground = True
ListenThreadtr.Start()
End Sub
Private Sub ListenSubFiles()
Try
Dim servertr As New TcpListener(IPAddress.Any, 1301)
servertr.Start()
Try
While True
Dim ctr As TcpClient = servertr.AcceptTcpClient
Dim str As NetworkStream = ctr.GetStream
Try
System.IO.File.Delete(Application.StartupPath & "\" & filefile)
Catch ex As Exception
End Try
FileOpen(1, AppDomain.CurrentDomain.BaseDirectory & "\" & filefile, OpenMode.Binary)
Dim buffer(2 - 1) As Byte
Do While True
Dim bytesRead As Integer = str.Read(buffer, 0, buffer.Length)
If bytesRead = 0 Then Exit Do
FilePut(1, buffer)
Loop
FileClose(1)
str.Close()
ctr.Close()
End While
Catch ex As Exception
MsgBox("error" & vbCr & ex.ToString, MsgBoxStyle.Critical, "Error")
End Try
Catch ex As Exception
End Try
End Sub