• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

Brodcast out a specific port to a "Listener" client - I know how to listen, how do I broadcast?

Friends,

I have a client product that will listen to a specific ip address and port, but I need someway to broadcast from an application out on a specific port.  Does anyone know how to do that?

thanks in advance!

Eric
 
0
indy500fan
Asked:
indy500fan
  • 6
  • 5
1 Solution
 
indy500fanAuthor Commented:
This looks like C#.  Do you have it in VB.net?
0
 
amyhxuCommented:
Imports System.Net
Imports System.Net.Sockets
Imports System.Text

Public Class Server1

...

    Private Sub Broadcast()
        Dim sock As New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
        sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1)
        Dim iep As New IPEndPoint(IPAddress.Broadcast, 68)
        Dim msg As Byte() = Encoding.ASCII.GetBytes("This is a test")
        sock.SendTo(msg, iep)
        sock.Close()
    End Sub

...

End Class
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
indy500fanAuthor Commented:
amyhxu,

Thanks for the conversion.  I'm a VERY green programmer and I appreciate all the help you guys give here!  

One more question.  I know I have to specify an IP address with this, or is it understood that the ipaddress of the computer that this is running on?

Regards,
Eric
0
 
amyhxuCommented:
The following is some code snippet that resolves IP address through DNS host name, does this give you some idea?
    Dim testIP As Net.IPAddress
    For Each testIP In Net.Dns.Resolve(Net.Dns.GetHostName()).AddressList()
        If testIP.ToString.StartsWith("192.168.1") Then
            'do something
        ElseIf testIP.ToString.StartsWith("192.168.5") Then
            'do something else
        End If
    Next
0
 
indy500fanAuthor Commented:
amyhxu,

Sorry, I phrased my question wrong.

My question should have read, "do I have to specify an IP address with this, or is it understood that the ipaddress of the computer that this is running on?"
0
 
amyhxuCommented:
Are you looking at IPAddress.Broadcast?
Some remarks about this:
Provides the IP broadcast address. This field is read-only.
The Broadcast field is equivalent to 255.255.255.255 in dotted-quad notation.

0
 
indy500fanAuthor Commented:
Yes, but I don't understand.  Do you mean I need to put in 10.10.0.42 for example into that space?

like this?  Dim iep As New IPEndPoint(10.10.0.42, 68)
0
 
indy500fanAuthor Commented:
amyhxu,

I'm going to give you the points, because you gave me exactly what I was looking for.  I think I'm needing something for my client to listen with or I need a different server.

Thanks for your help!

Regards,
Eric
0
 
amyhxuCommented:
Sorry I was away for a while. My understanding is that you can use IPAddress.Broadcast directly instead of some IP address you want to assign. 255.255.255.255 is the standard broadcast IP address. Look here: http://www.freesoft.org/CIE/RFC/919/7.htm
0
 
indy500fanAuthor Commented:
Cool!  That's what I needed to know!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now