-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
37 lines (29 loc) · 631 Bytes
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// This file is subject to a 1-clause BSD license.
// Its contents can be found in the enclosed LICENSE file.
package mitosis
import (
"fmt"
"net"
)
// spawnClient spawns a new client connection to the given server port.
func spawnClient(port uint, sf StateFunc) (err error) {
defer func() {
if x := recover(); x != nil {
if e, ok := x.(error); ok {
err = e
} else {
err = fmt.Errorf("%v", x)
}
}
}()
conn, err := net.Dial(protocol, fmt.Sprintf(":%d", port))
if err != nil {
return err
}
defer conn.Close()
writeRaw(conn, magick)
var state State
state.read(conn)
sf(&state)
return nil
}