mirror of
https://github.com/go-i2p/goSam.git
synced 2025-07-13 06:07:42 -04:00
NewClient now opens the TCP socket itself
This commit is contained in:
17
client.go
17
client.go
@ -4,6 +4,7 @@ import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
@ -13,11 +14,19 @@ type Client struct {
|
||||
toSam *bufio.Writer
|
||||
}
|
||||
|
||||
func NewClient(samConn io.ReadWriteCloser) (*Client, error) {
|
||||
func NewDefaultClient() (*Client, error) {
|
||||
return NewClient("localhost:7656")
|
||||
}
|
||||
|
||||
func NewClient(addr string) (*Client, error) {
|
||||
conn, err := net.Dial("tcp", addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c := &Client{
|
||||
samConn: samConn,
|
||||
fromSam: bufio.NewReader(samConn),
|
||||
toSam: bufio.NewWriter(samConn),
|
||||
samConn: conn,
|
||||
fromSam: bufio.NewReader(conn),
|
||||
toSam: bufio.NewWriter(conn),
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
package goSam
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
)
|
||||
import "testing"
|
||||
|
||||
var (
|
||||
client *Client
|
||||
@ -13,12 +10,7 @@ func setup() {
|
||||
var err error
|
||||
|
||||
// these tests expect a running SAM brige on this address
|
||||
conn, err := net.Dial("tcp", "localhost:7656")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client, err = NewClient(conn)
|
||||
client, err = NewDefaultClient()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user