Imports System.Net.Sockets
Imports System.Text.ASCIIEncoding
Public Class Form1
Dim client As TcpClient
Dim netstream As NetworkStream
Dim filenameselected As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
client = New TcpClient()
Try
Application.DoEvents()
client.Connect("127.0.0.1", 1000)
Catch ex As Exception
End Try
If client.Connected = True Then
netstream = client.GetStream
MsgBox("Connesso!")
Else
MsgBox("Connessione fallita!")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim open As New OpenFileDialog
If open.ShowDialog = Windows.Forms.DialogResult.OK Then
filenameselected = open.FileName
BackgroundWorker1.RunWorkerAsync()
End If
Catch ex As Exception
MsgBox(ErrorToString)
End Try
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Dim FileName As String = filenameselected
Dim Reader As New IO.FileStream(FileName, IO.FileMode.Open)
Dim Size As Int64 = FileLen(FileName)
Dim Bytes(4095) As Byte
If Size > 4096 Then
For Block As Int64 = 0 To Size Step 4096
If Size - Block >= 4096 Then
Reader.Read(Bytes, 0, 4096)
Else
Reader.Read(Bytes, 0, Size - Block)
End If
netstream.Write(Bytes, 0, 4096)
Threading.Thread.Sleep(30)
Next
End If
End Sub
End Class