Documentation ¶
Overview ¶
Package gtcp provides UDP server and client implementations.
Index ¶
- func NewNetConn(remoteAddress string, localAddress ...string) (*net.UDPConn, error)
- func Send(address string, data []byte, retry ...Retry) error
- func SendRecv(address string, data []byte, receive int, retry ...Retry) ([]byte, error)
- type Conn
- func (c *Conn) Recv(length int, retry ...Retry) ([]byte, error)
- func (c *Conn) RecvWithTimeout(length int, timeout time.Duration, retry ...Retry) (data []byte, err error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) Send(data []byte, retry ...Retry) (err error)
- func (c *Conn) SendRecv(data []byte, receive int, retry ...Retry) ([]byte, error)
- func (c *Conn) SendRecvWithTimeout(data []byte, receive int, timeout time.Duration, retry ...Retry) ([]byte, error)
- func (c *Conn) SendWithTimeout(data []byte, timeout time.Duration, retry ...Retry) (err error)
- func (c *Conn) SetDeadline(t time.Time) error
- func (c *Conn) SetRecvBufferWait(d time.Duration)
- func (c *Conn) SetRecvDeadline(t time.Time) error
- func (c *Conn) SetSendDeadline(t time.Time) error
- type Retry
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewNetConn ¶
NewNetConn creates and returns a *net.UDPConn with given addresses.
Types ¶
type Conn ¶
type Conn struct { *net.UDPConn // Underlying UDP connection. // contains filtered or unexported fields }
Conn handles the UDP connection.
func NewConn ¶
NewConn creates UDP connection to <remoteAddress>. The optional parameter <localAddress> specifies the local address for connection.
func NewConnByNetConn ¶
NewConnByNetConn creates a UDP connection object with given *net.UDPConn object.
func (*Conn) Recv ¶
Recv receives data from remote address.
Note that, 1. There's package border in UDP protocol, so we can receive a complete package if it specifies length < 0. 2. If length = 0, it means it receives the data from current buffer and returns immediately. 3. If length > 0, it means it blocks reading data from connection until length size was received.
func (*Conn) RecvWithTimeout ¶
func (c *Conn) RecvWithTimeout(length int, timeout time.Duration, retry ...Retry) (data []byte, err error)
RecvWithTimeout reads data from remote address with timeout.
func (*Conn) RemoteAddr ¶
RemoteAddr returns the remote address of current UDP connection. Note that it cannot use c.conn.RemoteAddr() as it's nil.
func (*Conn) SendRecvWithTimeout ¶
func (c *Conn) SendRecvWithTimeout(data []byte, receive int, timeout time.Duration, retry ...Retry) ([]byte, error)
SendRecvWithTimeout writes data to connection and reads response with timeout.
func (*Conn) SendWithTimeout ¶
SendWithTimeout writes data to connection with timeout.
func (*Conn) SetRecvBufferWait ¶
SetRecvBufferWait sets the buffer waiting timeout when reading all data from connection. The waiting duration cannot be too long which might delay receiving data from remote address.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the UDP server.
func GetServer ¶
func GetServer(name ...interface{}) *Server
GetServer creates and returns a UDP server instance with given name.
func NewServer ¶
NewServer creates and returns a UDP server. The optional parameter <name> is used to specify its name, which can be used for GetServer function to retrieve its instance.
func (*Server) SetAddress ¶
SetAddress sets the server address for UDP server.
func (*Server) SetHandler ¶
SetHandler sets the connection handler for UDP server.