btm
This commit is contained in:
parent
204d9ea182
commit
ad24ce236b
41
third_party/tcp/tcp_client.go
vendored
Normal file
41
third_party/tcp/tcp_client.go
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
package tcp
|
||||
|
||||
import "net"
|
||||
|
||||
type client struct {
|
||||
laddr *net.TCPAddr //local address
|
||||
raddr *net.TCPAddr //remote address
|
||||
con *net.TCPConn //tcp 连接
|
||||
}
|
||||
|
||||
func (c *client) NewClientWithLocal(remoteAddr string, localAddr string) *client {
|
||||
ra, raEr := net.ResolveTCPAddr("tcp", remoteAddr)
|
||||
if raEr != nil {
|
||||
panic(raEr)
|
||||
}
|
||||
c.raddr = ra
|
||||
//
|
||||
la, laEr := net.ResolveTCPAddr("tcp", localAddr)
|
||||
if laEr != nil {
|
||||
panic(laEr)
|
||||
}
|
||||
c.laddr = la
|
||||
return c
|
||||
}
|
||||
func (c *client) NewClient(remoteAddr string) *client {
|
||||
ra, raEr := net.ResolveTCPAddr("tcp", remoteAddr)
|
||||
if raEr != nil {
|
||||
panic(raEr)
|
||||
}
|
||||
c.raddr = ra
|
||||
c.con.LocalAddr()
|
||||
return c
|
||||
}
|
||||
func (c *client) Start() error {
|
||||
con, e := net.DialTCP(c.raddr.Network(), c.laddr, c.raddr)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
c.con = con
|
||||
return nil
|
||||
}
|
1
third_party/tcp/tcp_server.go
vendored
Normal file
1
third_party/tcp/tcp_server.go
vendored
Normal file
@ -0,0 +1 @@
|
||||
package tcp
|
Loading…
Reference in New Issue
Block a user