Merge branch 'master' of https://git.code.tencent.com/beijing-rtss-test/bj-rtsts-server-go
This commit is contained in:
commit
1c8379ada7
|
@ -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
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
package tcp
|
Loading…
Reference in New Issue