FAQ
AFAIK LookupAdr just looks up a list of addresses for e.g. a domain name
and multicast networking has no such thing as looking up all members of a
multicast group.
That wouldn't make much sense in a network where faults happen and
multicast groups can be arbitarily large.
If you want each client to know about any other client you'll have to make
them communicate with each other. For simplicity let's assume messages
don't get lost
(they do in reality however on say a LAN (not wireless) thats quite rare).
Then you could have all clients send their own address to the multicast
group announcing their presence. For more reliability you could do this
repeatably as a kind of heartbeat maybe making sure that not all clients
send their message at the same time.
Then you can have each client maintain a list of all known peers, scrubbing
all clients that it hasn't heart from in e.g. 3 heartbeattimes.
On Tuesday, February 26, 2013 12:41:36 PM UTC+1, Marius Westgaard wrote:

Hey

I want to know witch computers are connected to my multicast network:

package main

import (
"bufio"
"fmt"
"net"
"os"
"time"
)

func main() {
laddr, err := net.ResolveUDPAddr("udp", ":0")
mcaddr, err := net.ResolveUDPAddr("udp", "224.0.1.60:1888")
check(err)
conn, err := net.ListenMulticastUDP("udp", nil, mcaddr)
lconn, err := net.ListenUDP("udp", laddr)
check(err)
go listen(conn)
go write(conn, lconn, mcaddr)
go connections(mcaddr)
time.Sleep(1e15)
}

func listen(conn *net.UDPConn) {
for {
b := make([]byte, 256)
_, _, err := conn.ReadFromUDP(b)
check(err)
fmt.Println("read", string(b))
}
}

func write(conn, lconn *net.UDPConn, mcaddr *net.UDPAddr) {
reader := bufio.NewReader(os.Stdin)
for {
fmt.Print("Input: ")
txt, _, err := reader.ReadLine()
b := make([]byte, 256)
copy(b, txt)
check(err)
_, err = lconn.WriteToUDP(b, mcaddr)
check(err)
}
}

func connections(mcaddr *net.UDPAddr) {
for {
names, err := net.LookupAddr("224.0.1.60")
check(err)
nConnections := len(names)
fmt.Println(nConnections)
}
}

func check(err error) {
if err != nil {
panic(err)
}
}

I want the connections function to continously uppdate the names array
with the computers connected to the network, but it seems like i use the
wrong address as input to the LookupAddr function, witch address should i
use and how do i get it? i have been trying different ways to make the
mcaddr into a string and try using that as an input to the function. Is
what i am trying to do even possible?

What happens now is that each computer on the multicast only prints 1, and
only have their own name in the names list. I want to see the number of
connected computers and their names.

And yeah, i'm quite new to go, so any help would be much apreciated!
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 4 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedFeb 26, '13 at 12:35p
activeFeb 27, '13 at 2:39p
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase