func ClientConnection(clientsock *websocket.Conn) { packet := pnet.NewPacket() buffer := make([]uint8, pnet.PACKET_MAXSIZE) recv, err := clientsock.Read(buffer) if err == nil { copy(packet.Buffer[0:recv], buffer[0:recv]) packet.GetHeader() g_server.ParseFirstMessage(clientsock, packet) } else { if err.Error() != "EOF" { logger.Println("Client connection error: " + err.Error()) } } }
func echoHandler(ws *websocket.Conn) { buff := make([]byte, 150) fmt.Println("connected to:", ws.Config().Location.Host) for { _, err := ws.Read(buff) if err != nil { break } fmt.Println("got:", string(buff)) _, err = ws.Write(buff) if err != nil { break } } fmt.Println("lost connection with:", ws.Config().Location.Host) availableNodes <- reverseHostMap[ws.Config().Location.Host] }