kubo/daemon/daemon_client.go
2014-09-10 13:31:40 -07:00

30 lines
470 B
Go

package daemon
import (
"encoding/json"
"io"
"net"
"os"
"time"
)
//SendCommand connects to the address on the network with a timeout and encodes the connection into JSON
func SendCommand(command *Command, server string) error {
conn, err := net.DialTimeout("tcp", server, time.Millisecond*300)
if err != nil {
return err
}
enc := json.NewEncoder(conn)
err = enc.Encode(command)
if err != nil {
return err
}
io.Copy(os.Stdout, conn)
return nil
}