示例#1
0
// Accept creates a new Client and accepts a connection on it
func (c *Client) Accept() (net.Conn, error) {
	id, newAddr, err := c.CreateStreamSession("")
	if err != nil {
		return nil, err
	}

	fmt.Println("NewAddr:", newAddr)

	newC, err := NewDefaultClient()
	if err != nil {
		return nil, err
	}

	if ConnDebug {
		newC.SamConn = debug.WrapConn(newC.SamConn)
	}

	resp, err := newC.StreamAccept(id)
	if err != nil {
		return nil, err
	}

	fmt.Println("Accept Resp:", resp)

	return newC.SamConn, nil
}
示例#2
0
// NewClient creates a new client, connecting to a specified port
func NewClient(addr string) (*Client, error) {
	conn, err := net.Dial("tcp", addr)
	if err != nil {
		return nil, err
	}
	if ConnDebug {
		conn = debug.WrapConn(conn)
	}
	c := &Client{
		SamConn: conn,
		rd:      bufio.NewReader(conn),
	}
	return c, c.hello()
}