deregistering for clients
This commit is contained in:
parent
5f08c19c6b
commit
431e735870
|
@ -69,8 +69,7 @@ func runClient(cmd *cobra.Command, args []string) {
|
||||||
run := true
|
run := true
|
||||||
for run {
|
for run {
|
||||||
var oFrame data.Frame
|
var oFrame data.Frame
|
||||||
// always use new decoder - reusing may lead to errors
|
gd := gob.NewDecoder(con) // always use new decoder
|
||||||
gd := gob.NewDecoder(con)
|
|
||||||
err = gd.Decode(&oFrame)
|
err = gd.Decode(&oFrame)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("RGS:", err)
|
log.Println("RGS:", err)
|
||||||
|
|
|
@ -42,9 +42,8 @@ var clientKeys []int = make([]int, 100)
|
||||||
func handleConn(conn *net.TCPConn) {
|
func handleConn(conn *net.TCPConn) {
|
||||||
var hs data.Handshake
|
var hs data.Handshake
|
||||||
log.Println("Got a connection!")
|
log.Println("Got a connection!")
|
||||||
// handshake
|
dec := gob.NewDecoder(conn)
|
||||||
dec := gob.NewDecoder(conn) // Decoder
|
dec.Decode(&hs) // decode handshake
|
||||||
dec.Decode(&hs)
|
|
||||||
log.Println("Got client! ID:", hs.ID, "dimensions:", hs.W, hs.H)
|
log.Println("Got client! ID:", hs.ID, "dimensions:", hs.W, hs.H)
|
||||||
clientKeys = append(clientKeys, hs.ID)
|
clientKeys = append(clientKeys, hs.ID)
|
||||||
sort.Ints(clientKeys)
|
sort.Ints(clientKeys)
|
||||||
|
@ -68,8 +67,23 @@ func serveClients() {
|
||||||
id, client := k, clients[k]
|
id, client := k, clients[k]
|
||||||
if id > 0 {
|
if id > 0 {
|
||||||
enc := gob.NewEncoder(client.con)
|
enc := gob.NewEncoder(client.con)
|
||||||
enc.Encode(oFrame)
|
err := enc.Encode(oFrame)
|
||||||
|
if err != nil {
|
||||||
|
// client disconnected
|
||||||
|
|
||||||
|
//log.Println("BEFORE remove: clients:", clients, " clientKeys:", clientKeys)
|
||||||
|
|
||||||
|
// delete client
|
||||||
|
delete(clients, client.id)
|
||||||
|
|
||||||
|
// delete client key
|
||||||
|
// ugly as fuck in go to remove from a slice
|
||||||
|
// it *should* work though
|
||||||
|
idInKeys := sort.SearchInts(clientKeys, client.id)
|
||||||
|
clientKeys = append(clientKeys[:idInKeys], clientKeys[idInKeys+1:]...)
|
||||||
|
|
||||||
|
//log.Println("AFTER remove: clients:", clients, " clientKeys:", clientKeys)
|
||||||
|
}
|
||||||
//log.Println("ID:", id, "Client:", client)
|
//log.Println("ID:", id, "Client:", client)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user