FAQ
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

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 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