daemon_client.go 352 Bytes
Newer Older
1 2 3 4
package daemon

import (
	"encoding/json"
5
	"io"
6
	"net"
7
	"os"
Jeromy's avatar
Jeromy committed
8
	"time"
9 10
)

11
func SendCommand(com *Command, server string) error {
Jeromy's avatar
Jeromy committed
12
	con, err := net.DialTimeout("tcp", server, time.Millisecond*300)
13
	if err != nil {
14
		return err
15 16 17
	}

	enc := json.NewEncoder(con)
18
	err = enc.Encode(com)
19
	if err != nil {
20
		return err
21 22
	}

23
	io.Copy(os.Stdout, con)
24

25
	return nil
26
}