2022-01-10 17:11:30 +00:00
|
|
|
package net
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
2022-05-13 09:49:05 +00:00
|
|
|
"strconv"
|
2022-01-10 17:11:30 +00:00
|
|
|
)
|
|
|
|
|
2022-05-13 09:49:05 +00:00
|
|
|
func ListenTCP(network string, addr *TCPAddr) (Listener, error) {
|
|
|
|
l, err := net.ListenTCP(network, addr.Addr)
|
2022-01-10 17:11:30 +00:00
|
|
|
if err != nil {
|
|
|
|
return Listener{}, err
|
|
|
|
}
|
|
|
|
|
2022-01-11 17:15:45 +00:00
|
|
|
return Listener{listener: l}, nil
|
2022-01-10 17:11:30 +00:00
|
|
|
}
|
|
|
|
|
2022-05-13 09:49:05 +00:00
|
|
|
func DialTCP(network string, ip string, port string) (*Conn, error) {
|
2022-11-29 07:54:28 +00:00
|
|
|
p, _ := strconv.Atoi(port)
|
2022-05-13 09:49:05 +00:00
|
|
|
|
2022-11-29 07:54:28 +00:00
|
|
|
addr := &net.TCPAddr{
|
|
|
|
IP: net.ParseIP(ip),
|
|
|
|
Port: p,
|
|
|
|
}
|
2022-05-13 09:49:05 +00:00
|
|
|
|
|
|
|
conn, err := net.DialTCP(network, nil, addr)
|
2022-01-10 17:11:30 +00:00
|
|
|
if err != nil {
|
2022-01-13 16:06:14 +00:00
|
|
|
return &Conn{}, err
|
2022-01-10 17:11:30 +00:00
|
|
|
}
|
|
|
|
|
2022-01-13 16:06:14 +00:00
|
|
|
return &Conn{conn: conn}, nil
|
2022-01-10 17:11:30 +00:00
|
|
|
}
|