Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Network Broadcasting. How?

Network Broadcasting. How?

Scheduled Pinned Locked Moved C#
questionsysadminhelptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Roman Rodov
    wrote on last edited by
    #1

    Hi all, I have a question on how to properly implement network broadcasts. Our network is divided in subnets and I need help (it is probably more of a networking question than code) To broadcast I use this code: IPEndPoint ep = new IPEndPoint(IPAddress.Broadcast, 8300); UpdClient client = new UdpClient(); client.Send(...,ep); To receive I use this code: IPEndPoint ep = new IPEndPoint(IPAddress.Any, 0); UpdClient client = new UdpClient(8300); byte [] buffer = client.Receive(ref ep); My machine is on the 192.168.1.xxx subnet and all machines on the 1.xxx network receive the broadcast, but machines on the 192.168.8.xxx network do not. What IP address should I use in the sending portion to make sure I broadcast to the 8.xxx network?

    S L 2 Replies Last reply
    0
    • R Roman Rodov

      Hi all, I have a question on how to properly implement network broadcasts. Our network is divided in subnets and I need help (it is probably more of a networking question than code) To broadcast I use this code: IPEndPoint ep = new IPEndPoint(IPAddress.Broadcast, 8300); UpdClient client = new UdpClient(); client.Send(...,ep); To receive I use this code: IPEndPoint ep = new IPEndPoint(IPAddress.Any, 0); UpdClient client = new UdpClient(8300); byte [] buffer = client.Receive(ref ep); My machine is on the 192.168.1.xxx subnet and all machines on the 1.xxx network receive the broadcast, but machines on the 192.168.8.xxx network do not. What IP address should I use in the sending portion to make sure I broadcast to the 8.xxx network?

      S Offline
      S Offline
      Sebastian Schneider
      wrote on last edited by
      #2

      OK, this is how subnetting works: An IP-Address is 32 Bit long. The first part determines the Network, the second part identifies the Host. Your network class is C, which means: the first 24 Bit are Network, the last 8 Bit are host. Subnet-Mask is 255.255.255.0 (which means exactly the same: all bits set to 1 are part of the Network-ID, the bits set to 0 are part of the Host-ID. There never are any 0s between 1s, so its always ...11111000... and NEVER ...110110000... etc.) What is that subnet-mask good for, if the network-class already contains the necessary information? That is VERY simple: Using an IP-Address from ANY Network and the corresponding subnet mask, you can easily derive the broadcast-address of that network. Your code doesnt work cause IPAddress.Broadcast is 255.255.255.255 (which means "EVERY ADDRESS ON ALL NETWORKS" and is probably filtered by your L3-switches or routers). Try the following: If you need to contact all hosts in the 192.168.8.0 Network, use a bitwise-or of one host-address (e.g. 192.168.8.4) and the inverted subnet-mask (e.g. 0.0.0.255). That will return the broadcast-address of the network (in this case, 192.168.8.255). If you need to calculate the Network-Address, use a bitwise-and instead and dont invert the subnet-mask. Remember the following: The first address in a subnet always is the Network Address, the last address always is the Broadcast. If you are not using CIDR, the following is true: Subnetmask for Class-A Networks: 255.0.0.0 Subnetmask for Class-B Networks: 255.255.0.0 Subnetmask for Class-C Networks: 255.255.255.0 Cheers Sid

      1 Reply Last reply
      0
      • R Roman Rodov

        Hi all, I have a question on how to properly implement network broadcasts. Our network is divided in subnets and I need help (it is probably more of a networking question than code) To broadcast I use this code: IPEndPoint ep = new IPEndPoint(IPAddress.Broadcast, 8300); UpdClient client = new UdpClient(); client.Send(...,ep); To receive I use this code: IPEndPoint ep = new IPEndPoint(IPAddress.Any, 0); UpdClient client = new UdpClient(8300); byte [] buffer = client.Receive(ref ep); My machine is on the 192.168.1.xxx subnet and all machines on the 1.xxx network receive the broadcast, but machines on the 192.168.8.xxx network do not. What IP address should I use in the sending portion to make sure I broadcast to the 8.xxx network?

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #3

        AFAIK UDP multicast doesnt work over network boundries, IOW routers. You would have to implement some kind of proxy on the router to re-multicast to the other network segment. xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups