Imports System.Net.Sockets Imports System.Text Imports System.Net Imports System.IO Public Class mainform Private Sub SettingsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SettingsToolStripMenuItem.Click Dim s As New Input_settings s.update_settings(True) Me.Text = "Internet data transfer " & s.program & " application" End Sub Private Sub ShowFormToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowFormToolStripMenuItem.Click Me.Show() End Sub Private Sub UpdateHostToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateHostToolStripMenuItem.Click Dim d As New ftp_access d.display() End Sub Private Sub sendtextbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sendtextbutton.Click Dim t As New text_udp(Me) t.send_text() ' send whats in text box End Sub Private Sub HideToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HideToolStripMenuItem.Click help.Show() End Sub Private Sub Hide_form_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Hide_form.Click Me.Hide() End Sub Private Sub cancel_receive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancel_receive.Click file_tcp.receive_cancel = True End Sub Private Sub PictureBoxreceive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBoxreceive.Click Dim tcp As New file_tcp(Me) tcp.select_folder() End Sub Private Sub PictureBoxsend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBoxsend.Click If Cancel_Send.Enabled Then Exit Sub 'sending picture cant change Dim tcp As New file_tcp(Me) tcp.select_file() End Sub Private Sub Send_file_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Send_file.Click Dim tcp As New file_tcp(Me) tcp.send_file() End Sub Private Sub Cancel_Send_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Send.Click file_tcp.send_cancel = True End Sub Private Sub sendwake_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sendwake.Tick Dim t As New text_udp(Me) t.send_awake() text_udp.ready_ports = False checkports.Enabled = True 'check in 10 seconds to see if response End Sub Private Sub checkports_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles checkports.Tick checkports.Enabled = False 'only once If text_udp.ready_ports Then Exit Sub 'already have correct ports Dim d As New ftp_access d.display() 'need to check ports again End Sub Private Sub mainform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ftp_access.udp_ftp() 'set random udp port Dim tx As New text_udp(Me) 'start to listen on udp port tx.receive_text() Dim w As New Input_settings 'check settings If Not w.update_settings(False) Then Exit Sub ''cannot continue Me.Text = "Internet data transfer " & w.program & " application" Dim d As New ftp_access If d.display() Then tx.send_awake() 'if got remote port and ip can send awake End If End Sub Private Sub mainform_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown Me.Hide() End Sub Private Sub PictureBoxsend_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBoxsend.MouseEnter Label2.Text = "Select file to send" End Sub Private Sub PictureBoxsend_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBoxsend.MouseLeave Label2.Text = "" End Sub Private Sub PictureBoxreceive_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBoxreceive.MouseEnter Label3.Text = "Select folder to save file" End Sub Private Sub PictureBoxreceive_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBoxreceive.MouseLeave Label3.Text = "" End Sub End Class Imports System.IO Imports System.Security.Cryptography Public Class encript_decript Private Rijndael As New RijndaelManaged() 'symmetric encription class Public Function encript(ByVal value As String) As Byte() Return encript_byte(System.Text.Encoding.UTF8.GetBytes(value)) End Function 'string encription entry Public Function encript_byte(ByVal value As Byte()) As Byte() newkey() 'make key using password Dim Transform As ICryptoTransform = Rijndael.CreateEncryptor() 'get transform Dim fs As New MemoryStream() fs.Write(Rijndael.IV, 0, Rijndael.IV.Length) 'initialisation vector first Dim cs As New CryptoStream(fs, Transform, CryptoStreamMode.Write) Dim w As New System.IO.BinaryWriter(cs) 'write binary to crypto stream w.Write(value) 'send all data to binary writer w.Flush() cs.FlushFinalBlock() 'must fill last block with zeros Return fs.ToArray() w.Close() cs.Close() fs.Close() End Function Public Function decript(ByVal encoded As Byte()) As String Return System.Text.Encoding.UTF8.GetString(decript_byte(encoded)) End Function Public Function decript_byte(ByVal encoded As Byte()) As Byte() newkey() 'make key using password Dim fs = New MemoryStream(encoded) Dim IV As Byte() ReDim IV(Rijndael.IV.Length - 1) fs.Read(IV, 0, IV.Length) Rijndael.IV = IV 'got initialisation vector from file Dim Transform As ICryptoTransform = Rijndael.CreateDecryptor() Dim cs As New CryptoStream(fs, Transform, CryptoStreamMode.Read) Dim w As New System.IO.BinaryReader(cs) 'reads bytes from unencripted file decript_byte = w.ReadBytes(fs.Length) w.Close() cs.Close() fs.Close() End Function Private Sub newkey() 'make new key Dim Password As String = Input_settings.encript_pass 'use supplied password Dim Salt(7) As Byte ' use random value for the salt Dim Random As New RNGCryptoServiceProvider() Random.GetBytes(Salt) ' Use the password to create a key. Dim PDB As New PasswordDeriveBytes(Password, Salt) Dim Key() As Byte = PDB.CryptDeriveKey("RC2", "SHA", 128, Salt) Rijndael.Key = Key End Sub End Class Imports System.Net Imports System.Net.Sockets Imports System.IO Public Class file_tcp Public Sub New(ByVal f As mainform) _frm = f End Sub Private _frm As mainform 'need instance of mainform to give invoke a handle #Region "receive files" Public Shared file_receive() As Byte 'store for received file Public Shared dfile_receive() As Byte 'store for decripted received file Public Shared filereceive As String = "" Public Sub select_folder() If filereceive = "" _ Or mainform.cancel_receive.Enabled Then Exit Sub 'no file to save or busy Dim words = filereceive.Split("#") Dim dlg As New FolderBrowserDialog dlg.Description = "Select the folder to store the file " & words(0) If dlg.ShowDialog = DialogResult.OK Then My.Computer.FileSystem.WriteAllBytes(dlg.SelectedPath & "\" & words(0) _ , dfile_receive, True) End If End Sub Private Shared r_c As Boolean 'cancel receive operation Public Shared WriteOnly Property receive_cancel() As Boolean Set(ByVal value As Boolean) r_c = value 'cancel recieve when true End Set End Property Public Sub receive_file() Dim rx As New System.Threading.Thread(AddressOf accept) rx.IsBackground = True rx.Start() End Sub Private Sub accept() Dim wordsp = filereceive.Split("#") 'the tcp listen port sent by remote r_c = False Dim cancel As String = "" Dim Listen As New TcpListener(IPAddress.Parse(ftp_access.iplocal), wordsp(2)) Listen.Start() Dim Client As TcpClient = Listen.AcceptTcpClient() 'blocks until receive Dim Stream = Client.GetStream() Listen.Stop() 'we have connection stop listen _frm.Invoke(New recvdelegate(AddressOf startmessage), "Receiving " & filereceive & " from remote site") Try Dim words = filereceive.Split("#") Dim recbytes As Integer = 0 file_receive = New [Byte](words(1) - 1) {} Dim ten_display = 0, no_show = 0 'display every 10 seconds Dim groupsectionbytes As Integer = 0 'total in 10 seconds Do Until recbytes = words(1) 'length of file sent by remote site Dim sectionbytes = 0 System.Threading.Thread.Sleep(250) 'catchment time If Stream.DataAvailable Then sectionbytes = Stream.Read(file_receive, recbytes, _ file_receive.Length - recbytes) 'get whats available recbytes = recbytes + sectionbytes no_show = 0 'we have got data this second Else 'data no longer being sent no_show = no_show + 1 'missed data this second If no_show > 119 Then '30 seconds without data we must have Client.Close() 'lost connection so terminate all Stream.Close() cancel = "but" & vbNewLine & "Transfer stopped before all data received" End If End If ten_display = ten_display + 1 groupsectionbytes = groupsectionbytes + sectionbytes If ten_display = 39 Then 'only display every 10 seconds Dim recmsg = "Downloading " & filereceive & vbNewLine & _ "Received " & recbytes & " bytes..number of bytes left = " & _ words(1) - recbytes & vbNewLine & groupsectionbytes / 10 & " bytes per second" _frm.Invoke(New recvdelegate(AddressOf recvmessage), recmsg) ten_display = 0 'reset counter groupsectionbytes = 0 'reset bytes count End If If r_c Then 'receive cancel selected Client.Close() ' terminate all Stream.Close() cancel = "but" & vbNewLine & "Transfer cancelled before completion" System.Threading.Thread.CurrentThread.Abort() 'only need once End If Loop Catch ex As Exception 'connection severed by client Client.Close() ' terminate all Stream.Close() _frm.Invoke(New recvdelegate(AddressOf cancelmessage), "File transfere terminated by sender/receiver or connection failure" & vbNewLine & ex.ToString) System.Threading.Thread.CurrentThread.Abort() 'only need once Finally _frm.Invoke(New recvdelegate(AddressOf endrecvmessage), _ "The file received " & cancel) End Try Client.Close() ' terminate all Stream.Close() ' when a receive successful _frm.Invoke(New recvdelegate(AddressOf endrecvmessage), _ "The file received " & cancel) System.Threading.Thread.CurrentThread.Abort() 'only need once End Sub Delegate Sub recvdelegate(ByVal recmsg As String) Private Sub startmessage(ByVal recmsg As String) _frm.receiveTextBox.Text = recmsg _frm.cancel_receive.Enabled = True End Sub Private Sub cancelmessage(ByVal recmsg As String) _frm.receiveTextBox.Text = recmsg _frm.cancel_receive.Enabled = False End Sub Private Sub recvmessage(ByVal recmsg As String) _frm.receiveTextBox.Text = recmsg End Sub Private Sub endrecvmessage(ByVal recmsg As String) _frm.receiveTextBox.Text = recmsg 'show complete _frm.cancel_receive.Enabled = False Try 'show if an image Dim cr As New encript_decript 'encript and decript web details dfile_receive = cr.decript_byte(file_receive) Dim ms As New System.IO.MemoryStream(dfile_receive) _frm.PictureBoxreceive.Image = Image.FromStream(ms) ms.Close() 'dont need now Catch ex As Exception _frm.PictureBoxreceive.Image = My.Resources.filepicture End Try End Sub #End Region #Region "send files" Public Shared file_data() As Byte 'store for the file to be sent Public Shared filesend As String = "" 'store for send file name and length Public Sub select_file() Dim dlg As New OpenFileDialog dlg.Title = "Select a file to send to the remote site" If dlg.ShowDialog = DialogResult.OK Then file_data = My.Computer.FileSystem.ReadAllBytes(dlg.FileName) mainform.receiveTextBox.Text = dlg.FileName filesend = System.IO.Path.GetFileName(dlg.FileName) _ & "#" & file_data.Length.ToString 'file name and length Try mainform.PictureBoxsend.Image = Image.FromFile(dlg.FileName) Catch ex As Exception mainform.PictureBoxsend.Image = My.Resources.filepicture End Try mainform.Send_file.Enabled = True 'can now send file End If End Sub Private Shared s_c As Boolean 'cancel send operation Public Shared WriteOnly Property send_cancel() As Boolean Set(ByVal value As Boolean) s_c = value 'cancel send when true End Set End Property Public Sub send_file() Dim tx As New System.Threading.Thread(AddressOf Tsend_file) _frm.receiveTextBox.Text = "File " & filesend & " bytes upload starting" tx.IsBackground = True tx.Start() _frm.Send_file.Enabled = False _frm.Cancel_Send.Enabled = True End Sub Private Sub Tsend_file() s_c = False Dim this_port = tcp_port() Dim cr As New encript_decript 'encript and decript web details Dim dfile_data = cr.encript_byte(file_data) Dim dwords() = filesend.Split("#") 'the encripted file may have more bytes Dim dfilesend = dwords(0) & "#" & dfile_data.Length text_udp.s_t(Convert.ToChar(&H25C4).ToString & dfilesend & "#" & this_port) 'send file data to remote System.Threading.Thread.Sleep(5000) 'give it plenty of time to receive the file info Try 'to see if server is available Dim words() As String words = ftp_access.remote_ports.Split("@") 'rid of udp and ip Dim client As New TcpClient client.Connect(IPAddress.Parse(words(0)), this_port) Dim Stream = client.GetStream() ' Retrieve the network stream. Dim count = 0, countnext = 0, size = 29200 'the size of chuncks to send Do Dim sw As Stopwatch = Stopwatch.StartNew() If dfile_data.Length < size Then size = dfile_data.Length countnext = count + size If countnext > dfile_data.Length Then size = size - countnext + dfile_data.Length Stream.Write(dfile_data, count, size) If countnext > dfile_data.Length Then Exit Do count = countnext If s_c Then Stream.Close() client.Close() System.Threading.Thread.CurrentThread.Abort() 'finish with this file End If 'System.Threading.Thread.Sleep(1000) 'simulate net speed _frm.Invoke(New senddelegate(AddressOf sendingmessage), "Transfering " _ & filesend & vbNewLine & "Uploaded " & count _ & " bytes..number of bytes left = " & dfile_data.Length - count _ & vbNewLine & CInt(size * 1000 / (sw.ElapsedMilliseconds + 1)) & " bytes per second") Loop _frm.Invoke(New senddelegate(AddressOf completemessage), "") Stream.Close() client.Close() Catch ex As Exception _frm.Invoke(New senddelegate(AddressOf errormessage), ex.ToString) End Try System.Threading.Thread.CurrentThread.Abort() 'finish with this file send End Sub Private Function tcp_port() As String Dim rg As New Random Dim words() As String words = ftp_access.remote_ports.Split("@") tcp_port = rg.Next(4000, 9999) Do 'not same as udp Try If tcp_port <> words(2).Substring(3) Then Exit Do Catch ex As Exception _frm.Invoke(New senddelegate(AddressOf errormessage), ex.ToString) System.Threading.Thread.CurrentThread.Abort() 'ports not ready End Try Loop End Function Delegate Sub senddelegate(ByVal msg As String) Private Sub errormessage(ByVal msg As String) _frm.receiveTextBox.Text = "Cant send file. Cancelled by sender/receiver or connection failure" & vbNewLine & msg _frm.Send_file.Enabled = True _frm.Cancel_Send.Enabled = False End Sub Private Sub completemessage(ByVal msg As String) _frm.receiveTextBox.Text = "File upload complete" _frm.Send_file.Enabled = True _frm.Cancel_Send.Enabled = False End Sub Private Sub sendingmessage(ByVal msg As String) _frm.receiveTextBox.Text = msg End Sub #End Region End Class Imports System.Net.Sockets Imports System.Text Imports System.Net Imports System.IO Imports System.Net.NetworkInformation Public Class ftp_access Private store_ip As String = "" Private store_success As Boolean = False Public Shared remote_ports As String = "" 'remote ip@time@udp@tcp Private return_success As Boolean = False Public Shared iplocal As String = "" 'local ip Public Shared session_ports As String = "" 'local @udp@tcp ports Dim cr As New encript_decript 'encript and decript web details Public Function display() As Boolean display = False update_site() If local_ip() = "127.0.0.1" Then mainform.Label1.Text = "Not connected to the internet" & vbNewLine Else : mainform.Label1.Text = "Connected to internet. IP address is " & local_ip() & vbNewLine End If If store_success Then mainform.Label1.Text = mainform.Label1.Text & ("Your details stored on host site" & _ vbNewLine & store_ip & vbNewLine) Else : mainform.Label1.Text = mainform.Label1.Text & "Your details are not stored on host site" & vbNewLine End If If return_success Then mainform.Label1.Text = mainform.Label1.Text & "Remote site details returned from host site" _ & vbNewLine & remote_ports & vbNewLine Else : mainform.Label1.Text = mainform.Label1.Text & "Remote site details not returned from host site" & vbNewLine End If If store_success And return_success Then display = True End Function Public Sub update_site() Dim w As New Input_settings w.update_settings(False) 'get the host site details iplocal = local_ip() If iplocal = "127.0.0.1" Then Exit Sub store_ip = iplocal & "@" & DateTime.Now.ToString("hh:mm:ss...dd/MM/yyyy") _ & session_ports Dim filename = "client.txt" If w.program = "server" Then filename = "server.txt" Dim url = w.host & filename Dim fileup = My.Computer.FileSystem.GetTempFileName Try store_success = True 'assume sucess My.Computer.FileSystem.WriteAllBytes(fileup, cr.encript(store_ip), False) My.Computer.Network.UploadFile(fileup, url, w.user, w.pass, False, 60000) File.Delete(fileup) Catch ex As Exception mainform.receiveTextBox.Text = _ "Host access did not work. Check your settings and then update host" & vbNewLine & ex.ToString store_success = False 'did not work End Try filename = "server.txt" If w.program = "server" Then filename = "client.txt" url = w.host & filename Dim filedown = My.Computer.FileSystem.GetTempFileName Try return_success = True My.Computer.Network.DownloadFile(url, filedown, w.user, w.pass, False, 60000, True) remote_ports = cr.decript(My.Computer.FileSystem.ReadAllBytes(filedown)) File.Delete(filedown) Catch ex As Exception mainform.receiveTextBox.Text = _ "Host access did not work. Remote site may not be working" & vbNewLine & _ " Check your settings and then update host" & vbNewLine & ex.ToString return_success = False End Try End Sub Public Function local_ip() As String Dim host = System.Net.Dns.GetHostName Try local_ip = System.Net.Dns.GetHostEntry(host).AddressList(1).ToString Catch ex As Exception local_ip = System.Net.Dns.GetHostEntry(host).AddressList(0).ToString End Try If local_ip <> "127.0.0.1" Then Dim nics As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces() Dim properties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties() Dim adapter As NetworkInterface Dim ipprops As IPInterfaceProperties Dim unicoll As UnicastIPAddressInformationCollection = Nothing Dim uni As UnicastIPAddressInformation For Each adapter In nics ipprops = adapter.GetIPProperties() unicoll = ipprops.UnicastAddresses For Each uni In unicoll If Not uni.Address.IsIPv6LinkLocal Then local_ip = uni.Address.ToString Exit Function End If Next Next End If End Function Public Shared Sub udp_ftp() Dim rg As New Random() session_ports = "@udp" & rg.Next(4000, 9999) 'keep port witin these bounds End Sub End Class Public Class Input_settings Public Shared encript_pass As String = "" Private program_type As String = "" Private host_name As String = "" Private user_name As String = "" Private pass_word As String = "" Public ReadOnly Property program() As String Get program = program_type End Get End Property Public ReadOnly Property host() As String Get host = host_name End Get End Property Public ReadOnly Property user() As String Get user = user_name End Get End Property Public ReadOnly Property pass() As String Get pass = pass_word End Get End Property Public Function update_settings(ByVal show As Boolean) As Boolean Dim cr As New encript_decript 'encript and decript web details update_settings = True 'assume it will have web site details Dim Uencript_pass As String = "" Try 'also detects if any changes to data in regestry encript_pass = "abcdefg" 'this is default password stores password Uencript_pass = cr.decript(My.Computer.Registry.GetValue("HKEY_CURRENT_USER\software\carl47_settings\" _ , "encript_pass", "")) Catch ex As Exception End Try 'the registry might have been altered Dim bencript_pass() As Byte If Uencript_pass = "" Or show Then epass.TextBox1.Text = Uencript_pass 'this is the stored If epass.ShowDialog() = Windows.Forms.DialogResult.OK Then bencript_pass = cr.encript(epass.TextBox1.Text) encript_pass = epass.TextBox1.Text 'use the user password Else 'stays at "abcdefg" if user dose not change encript_pass = "abcdefg" bencript_pass = cr.encript("abcdefg") End If 'stays at "abcdefg" if user dose not change My.Computer.Registry.SetValue("HKEY_CURRENT_USER\software\carl47_settings\", _ "encript_pass", bencript_pass) 'set pass Else : encript_pass = Uencript_pass 'use the existing password End If Try 'also detects if any changes to data in regestry program_type = cr.decript(My.Computer.Registry.GetValue("HKEY_CURRENT_USER\software\carl47_settings\" _ , "program_type", "")) Catch ex As Exception End Try 'the registry might have been altered If program_type = "client" Or program_type = "server" Then Else : program_type = "" End If 'the program type must be exactly one or other Try host_name = cr.decript(My.Computer.Registry.GetValue("HKEY_CURRENT_USER\software\carl47_settings\" _ , "host_name", "")) 'decript throws if data is not as coded Catch ex As Exception End Try 'the registry might have been altered Try user_name = cr.decript(My.Computer.Registry.GetValue("HKEY_CURRENT_USER\software\carl47_settings\" _ , "user_name", "")) 'decript throws if data is not as coded Catch ex As Exception End Try 'the registry might have been altered Try pass_word = cr.decript(My.Computer.Registry.GetValue("HKEY_CURRENT_USER\software\carl47_settings\" _ , "pass_word", "")) Catch ex As Exception End Try 'the registry might have been altered If user_name = "" Or pass_word = "" Or program_type = "" _ Or host_name = "" Or show Then 'get these from user input.TextBox3.Text = host_name input.TextBox1.Text = user_name 'put what we have into diaglog box input.TextBox2.Text = pass_word If program_type = "server" Then input.RadioButton2.Checked = True Do 'try until canceled or correctly input If input.ShowDialog() = Windows.Forms.DialogResult.OK Then If (Not input.TextBox1.Text = "") And (Not input.TextBox2.Text = "") _ And (Not input.TextBox3.Text = "") Then Dim bhost_name = cr.encript(input.TextBox3.Text) Dim buser_name = cr.encript(input.TextBox1.Text) Dim bpass_word = cr.encript(input.TextBox2.Text) 'encript before user_name = cr.decript(buser_name) pass_word = cr.decript(bpass_word) 'set the enencripted values My.Computer.Registry.CurrentUser.CreateSubKey("software\carl47_settings") My.Computer.Registry.SetValue("HKEY_CURRENT_USER\software\carl47_settings\", _ "host_name", bhost_name) 'set host My.Computer.Registry.SetValue("HKEY_CURRENT_USER\software\carl47_settings\", _ "user_name", buser_name) 'set user My.Computer.Registry.SetValue("HKEY_CURRENT_USER\software\carl47_settings\", _ "pass_word", bpass_word) 'set If input.RadioButton2.Checked Then program_type = "server" _ Else program_type = "client" Dim bprogram_type = cr.encript(program_type) My.Computer.Registry.SetValue("HKEY_CURRENT_USER\software\carl47_settings\", _ "program_type", bprogram_type) 'set Exit Do 'data inputed End If Else If (MessageBox.Show("The program cant operate without a web site" _ & vbNewLine & "Cancel and close program", "Cancel or Retry", _ MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation)) _ = DialogResult.Cancel Then update_settings = False Exit Do 'no details so cant work program End If End If Loop 'wait until the user and password entered End If End Function End Class Imports System.Net.Sockets Imports System.Net Imports System.IO Public Class text_udp Public Sub New(ByVal f As mainform) _frm = f End Sub Private _frm As mainform 'need instance of mainform to give invoke a handler Public Shared ready_ports As Boolean = False 'is remote responding Private Shared sw As New Stopwatch Public Sub send_awake() sw.Start() s_t(Convert.ToChar(&H25B2).ToString & "Remote site can send you text as at" & vbNewLine _ & DateTime.Now.ToString("hh:mm:ss...dd/MM/yyyy")) End Sub Public Sub reply_text(ByVal msg As String) s_t(Convert.ToChar(&H25BA).ToString & msg) End Sub Public Sub send_text() sw.Start() 'see how long before responds _frm.receiveTextBox.Text = "Cant raise the remote site" & vbNewLine _ & "May have wrong ports try update host" & vbNewLine _ & "You may have to wait till the remote updates" s_t(_frm.sendTextBox.Text) End Sub Public Shared Sub s_t(ByVal msg As String) Dim cr As New encript_decript 'encript and decript web details Try Dim words() As String words = ftp_access.remote_ports.Split("@") 'rid of udp and ip Dim client As New UdpClient 'remote ip and udp port Dim rep As New IPEndPoint(IPAddress.Parse(words(0)), words(2).Substring(3)) Dim data = cr.encript(msg) client.Send(data, data.Length, rep) client.Close() Catch ex As Exception End Try End Sub Public Sub receive_text() Dim RX As New System.Threading.Thread(AddressOf remoteRX) RX.IsBackground = True RX.Start() 'listen for respose to query End Sub Private Sub remoteRX() 'blocks until data received Dim cr As New encript_decript 'encript and decript web details Dim words() As String 'get rid of udp words = ftp_access.session_ports.Split("@") 'get the home udp port Dim client As New UdpClient(CInt(words(1).Substring(3))) 'listen on this port Do Try Dim data() As Byte data = client.Receive(Nothing) Dim msg = cr.decript(data) _frm.Invoke(New messdelegate(AddressOf showmessage), msg) Catch ex As Exception End Try Loop End Sub Delegate Sub messdelegate(ByVal msg As String) Private Sub showmessage(ByVal msg As String) If msg.Substring(0, 1) = Convert.ToChar(&H25C4).ToString Then file_tcp.filereceive = msg.Substring(1) Dim rx As New file_tcp(mainform) 'start to listen on tcp port rx.receive_file() Else If msg.Substring(0, 1) = Convert.ToChar(&H25BA).ToString Or _ msg.Substring(0, 1) = Convert.ToChar(&H25B2).ToString Then _frm.receiveTextBox.Text = msg 'display the sent replies Else : _frm.usertext_receive.Text = msg 'display the sent text End If If msg.Substring(0, 1) <> Convert.ToChar(&H25BA).ToString Then 'is a reply message If msg.Substring(0, 1) <> Convert.ToChar(&H25B2).ToString Then reply_text("The remote site has received your text") 'send received text mainform.Show() Else reply_text("The remote site has received your wakeup text") 'send wakeup text End If Else ready_ports = True 'the ports must be right _frm.receiveTextBox.Text &= vbNewLine & " Responded in " & sw.ElapsedMilliseconds & " millisecs" sw.Reset() End If End If End Sub End Class