vignesh.a.p
New member
- Joined
- Mar 15, 2007
- Messages
- 2
- Programming Experience
- Beginner
I'm working on a LAN file transfer application. I've established a TCP connection through TCP client and listener. I then used stream to send data. It worked fine for small files. But when I tried for larger files by sending chunks per instance it showed an exception error. I used timer to loop it. Here is the code...
Code:
The real problem is when this timer ticks for first time it sends 2048 bytes. But for second time the highlighted line produces cannot write error. Watch window shows that
my sendclient.connected = true for first time and second time its false.
why does it disconnect automatically? is there any other better way to do my transfer.. kindly help!
Code:
Private Sub sendtimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sendtimer.Tick
sendcount += 1
If sendcount <= Math.Truncate(sendsize / 2048) Then '2048 buffer
Dim filetonet(2047) As Byte
sendfile.Read(filetonet, 0, 2048)
sendstream.Write(filetonet, 0, 2048)
ElseIf remain <> 0 Then
Dim filetonet(remain - 1) As Byte
sendfile.Read(filetonet, 0, filetonet.Length)
sendstream.Write(filetonet, 0, filetonet.Length)
'post send operations
sendtimer.Enabled = False
status.Text = "File Sent"
sendfile.Close()
sendstream.Dispose()
sendclient.Close()
Else
'post send operations
sendtimer.Enabled = False
sendfile.Close()
status.Text = "File Sent"
sendstream.Dispose()
sendclient.Close()
End If
End Sub
sendcount += 1
If sendcount <= Math.Truncate(sendsize / 2048) Then '2048 buffer
Dim filetonet(2047) As Byte
sendfile.Read(filetonet, 0, 2048)
sendstream.Write(filetonet, 0, 2048)
ElseIf remain <> 0 Then
Dim filetonet(remain - 1) As Byte
sendfile.Read(filetonet, 0, filetonet.Length)
sendstream.Write(filetonet, 0, filetonet.Length)
'post send operations
sendtimer.Enabled = False
status.Text = "File Sent"
sendfile.Close()
sendstream.Dispose()
sendclient.Close()
Else
'post send operations
sendtimer.Enabled = False
sendfile.Close()
status.Text = "File Sent"
sendstream.Dispose()
sendclient.Close()
End If
End Sub
The real problem is when this timer ticks for first time it sends 2048 bytes. But for second time the highlighted line produces cannot write error. Watch window shows that
my sendclient.connected = true for first time and second time its false.
why does it disconnect automatically? is there any other better way to do my transfer.. kindly help!