Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 517
  • Last Modified:

Broadcast string to all clients

I'm working on a notification program in VB.NET 2010(Client). What I'm looking to do is make an ASP.NET page or just another VB Windows Application(Server) that can be used to broadcast a string to all clients on the subnet and I need to have the Client display that string. whats the simplist way to do this? I'm looking for very simple code that gets the job done.
0
MaximumIQ
Asked:
MaximumIQ
  • 4
  • 3
1 Solution
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Hello, I did this example for you, I think that is the simples way to do that:
Module Module1
    Sub Main()
        Dim thServer As New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf ImTheServer))
        Dim thClient As New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf ImTheClient))

        thServer.Start()
        thClient.Start()

        thServer.Join()
        thClient.Join()
    End Sub

    Sub ImTheServer()
        Dim server As New System.Net.Sockets.UdpClient

        ' Im using port 50000
        Dim endPoint As New System.Net.IPEndPoint(System.Net.IPAddress.Broadcast, 50000)

        ' Send it 10 times
        For index As Integer = 1 To 10
            Dim text As String = "Hello there!!! " & index
            Dim textBytes() As Byte = System.Text.Encoding.ASCII.GetBytes(text)

            Console.WriteLine("Server says: " & text)

            ' Send it!
            server.Send(textBytes, textBytes.Length, endPoint)

            ' Wait 1 sec...
            System.Threading.Thread.Sleep(1000)
        Next
    End Sub

    Sub ImTheClient()
        'Your server IP (for demo purpouses Im using System.Net.IPAddress.Loopback (127.0.0.1))
        Dim endPointMyServer As New System.Net.IPEndPoint(System.Net.IPAddress.Loopback, 50000)

        ' Listen in port 50000
        Dim client As New System.Net.Sockets.UdpClient(50000)

        Do While True
            Console.WriteLine("Client waiting...")
            ' Listening...
            Dim textBytes() As Byte = client.Receive(endPointMyServer)
            Console.WriteLine("Client listened: " & System.Text.Encoding.ASCII.GetString(textBytes))
        Loop
    End Sub
End Module

Open in new window


Or downloads the project from this link:
http://dl.dropbox.com/u/13237304/NetServerClientTest.zip

I'm using UDP so it cannot guarantee that the message is delivered.
I hope this help.
0
 
MaximumIQAuthor Commented:
Works perfectly. Thank you
0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Glad to help buddy!
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
MaximumIQAuthor Commented:
The program im intergrating this into does other features. As soon as the Client is started, it stops doing everything else. Is there a way to make the client run in the background where my program would continue executing while the clienting is listening?
0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Hello buddy, yes, use the same way that I use in the example, just make sure to set the property IsBackground true, in your client app call the listener like this:

Dim thClient As New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf ImTheClient))
thClient.IsBackground = true
thClient.Start()
0
 
MaximumIQAuthor Commented:
I tried that and i'm still having the same problem. It basically stop executing everything else once this line runs
thClient.Join()

I tried without it and the listener still seems to work, so I'm just leaving that line out.

Thanks again for your help yv989c
0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Exactly buddy, that is what you needed to do, sorry if I dint explain well.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now