Die DLL ist auf der Site "http://www.codeproject.com/KB/IP/TinyUDP.aspx" beschrieben und kann von hier auch runtergeladen werden.
Grüße
RobertS
Code: Alles auswählen
Imports Tiny.UDP ' TinyNET.dll from http://www.codeproject.com/KB/IP/TinyUDP.aspx
Imports System.Net
Imports System.Net.Sockets
Public Class Form1
Inherits System.Windows.Forms.Form
Dim server As New TinyServer
Dim WithEvents client As TinyClient
Dim ReadString As String = "" ' Zeichenbuffer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Show()
server.ClientPort = 75 ' Sende Port
server.Protocol = ProtocolType.Udp
server.Encode = EncodingType.ASCII
client = New TinyClient ' Client Objekt erstellen
client.ClientPort = 77 ' Empfangs Port
client.Protocol = ProtocolType.Udp
client.Encode = EncodingType.ASCII
Timer1.Enabled = True ' Der Client startet einen eigenen Prozess und muss deshalb etwas verzögert starten
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Try
client.Stop() ' Prozess beenden
Catch ex As Exception
End Try
End
End Sub
Private Sub client_AfterReceive(ByVal sender As Object, ByVal e As System.EventArgs) Handles client.AfterReceive
ReadString = client.Message ' Zeichen vom Client-Thread buffern
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
client.Start() ' Client Start
Me.Text = "Listen at Port: " & client.ClientPort ' Port anzeigen
Timer2.Enabled = True ' Empfangs-Anzeige-Timer starten
server.ClientAddress = IPAddress.Parse("255.255.255.255") ' Broadcast IP einstellen
server.SendMessage("wer da?" + vbCrLf) ' Broadcast Komando senden
server.SendMessage("wer da?" + vbCrLf) ' Muß 2 Mal gesendet werden
server.ClientAddress = IPAddress.Parse("123.123.221.26") ' Steckdosen IP einstellen
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If Len(ReadString) > 0 Then ' Empfangene Zeichen ?
TextBox1.Text += ReadString ' Anzeigen
ReadString = "" ' Buffer zurücksetzen
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
server.SendMessage("wer da?" + vbCrLf) ' Status abfragen
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
server.SendMessage("Sw_on1user" & Chr(0) & vbCrLf) ' Einschalten
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
server.SendMessage("Sw_off1user" & Chr(0) & vbCrLf) ' Ausschalten
End Sub
End Class