P
Parisa_1
Guest
Hello,
I am going to create an active lan devices application in VB.NET. Here is my code:
Imports System.Threading, System.Net.Sockets, System.Text, System.IO, System.Net
Public Class Form1
Dim th As Thread
Dim sock As UdpClient
Dim ip As String = "255.255.255.255"
Dim port As Integer = 1901
Dim Aux As String
Dim SearchVar() As Byte = {&HFF, &H1, &H1, &H2}
Private Sub search()
Dim IpEnd As IPEndPoint = New IPEndPoint(IPAddress.Any, 100)
Try
Do
Dim bytes() As Byte = sock.Receive(IpEnd)
Aux = Encoding.Default.GetString(bytes)
If Aux <> "" Then
Me.Invoke(New EventHandler(AddressOf add))
Aux = ""
End If
Loop
Catch ex As Exception
End Try
End Sub
Private Sub add()
ListBox1.Items.Add(Aux)
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
sock = New UdpClient
sock.Connect(ip, port)
sock.Send(SearchVar, SearchVar.Length)
th = New Thread(AddressOf Me.search)
th.Start()
End Sub
End Class
Here is output of my application which no device responses to me.
In contrast, A similar application has these results.
what is my mistake?
Continue reading...
I am going to create an active lan devices application in VB.NET. Here is my code:
Imports System.Threading, System.Net.Sockets, System.Text, System.IO, System.Net
Public Class Form1
Dim th As Thread
Dim sock As UdpClient
Dim ip As String = "255.255.255.255"
Dim port As Integer = 1901
Dim Aux As String
Dim SearchVar() As Byte = {&HFF, &H1, &H1, &H2}
Private Sub search()
Dim IpEnd As IPEndPoint = New IPEndPoint(IPAddress.Any, 100)
Try
Do
Dim bytes() As Byte = sock.Receive(IpEnd)
Aux = Encoding.Default.GetString(bytes)
If Aux <> "" Then
Me.Invoke(New EventHandler(AddressOf add))
Aux = ""
End If
Loop
Catch ex As Exception
End Try
End Sub
Private Sub add()
ListBox1.Items.Add(Aux)
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
sock = New UdpClient
sock.Connect(ip, port)
sock.Send(SearchVar, SearchVar.Length)
th = New Thread(AddressOf Me.search)
th.Start()
End Sub
End Class
Here is output of my application which no device responses to me.
In contrast, A similar application has these results.
what is my mistake?
Continue reading...