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

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

Siraj Ravel's avatar
Siraj Ravel committed
11 12 13 14 15 16

//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)
	
17
	if err != nil {
18
		return err
19 20
	}

Siraj Ravel's avatar
Siraj Ravel committed
21 22
	enc := json.NewEncoder(conn)
	err = enc.Encode(command)
23
	if err != nil {
24
		return err
25 26
	}

Siraj Ravel's avatar
Siraj Ravel committed
27
	io.Copy(os.Stdout, conn)
28

29
	return nil
30
}