Documentation
¶
Index ¶
- func ErrConnectionClosed(err error) bool
- func ErrReadTimeout(err error) bool
- func Ping(address string) (response []byte, err error)
- type Conn
- func (conn *Conn) Close() error
- func (conn *Conn) Latency() time.Duration
- func (conn *Conn) LocalAddr() net.Addr
- func (conn *Conn) Read(b []byte) (n int, err error)
- func (conn *Conn) RemoteAddr() net.Addr
- func (conn *Conn) SetDeadline(t time.Time) error
- func (conn *Conn) SetReadDeadline(t time.Time) error
- func (conn *Conn) SetWriteDeadline(time.Time) error
- func (conn *Conn) Write(b []byte) (n int, err error)
- type Dialer
- type Listener
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrConnectionClosed ¶
ErrConnectionClosed checks if the error passed was an error caused by reading from a Conn of which the connection was closed.
func ErrReadTimeout ¶
ErrReadTimeout checks if the error passed was an error caused by a timeout set when reading from the Conn. noinspection GoUnusedExportedFunction
func Ping ¶
Ping sends a ping to an address and returns the response obtained. If successful, a non-nil response byte slice containing the data is returned. If the ping failed, an error is returned describing the failure. Note that the packet sent to the server may be lost due to the nature of UDP. If this is the case, an error is returned which implies a timeout occurred. sendPing fills out a Dialer struct with raknet.currentProtocol as protocol.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn represents a connection to a specific client. It is not a real connection, as UDP is connectionless, but rather a connection emulated using RakNet. Methods may be called on Conn from multiple goroutines simultaneously.
func Dial ¶
Dial attempts to dial a RakNet connection to the address passed. The address may be either an IP address or a hostname, combined with a port that is separated with ':'. Dial will attempt to dial a connection within 10 seconds. If not all packets are received after that, the connection will timeout and an error will be returned. Dial fills out a Dialer struct with a default error logger and raknet.currentProtocol as protocol.
func (*Conn) Close ¶
Close closes the connection. All blocking Read or Write actions are cancelled and will return an error.
func (*Conn) Latency ¶
Latency returns a rolling average of latency between the sending and the receiving end of the connection. The latency returned is updated continuously and is half the round trip time (RTT).
func (*Conn) LocalAddr ¶
LocalAddr returns the local address of the connection, which is always the same as the listener's.
func (*Conn) Read ¶
Read reads from the connection into the byte slice passed. If successful, the amount of bytes read n is returned, and the error returned will be nil. Read blocks until a packet is received over the connection, or until the session is closed or the read times out, in which case an error is returned.
func (*Conn) RemoteAddr ¶
RemoteAddr returns the remote address of the connection, meaning the address this connection leads to.
func (*Conn) SetDeadline ¶
SetDeadline sets the deadline of the connection for both Read and Write. SetDeadline is equivalent to calling both SetReadDeadline and SetWriteDeadline.
func (*Conn) SetReadDeadline ¶
SetReadDeadline sets the read deadline of the connection. An error is returned only if the time passed is before time.Now(). Calling SetReadDeadline means the next Read call that exceeds the deadline will fail and return an error. Setting the read deadline to the default value of time.Time removes the deadline.
func (*Conn) SetWriteDeadline ¶
SetWriteDeadline has no behaviour. It is merely there to satisfy the net.Conn interface.
func (*Conn) Write ¶
Write writes a buffer b over the RakNet connection. The amount of bytes written n is always equal to the length of the bytes written if the write was successful. If not, an error is returned and n is 0. Write may be called simultaneously from multiple goroutines, but will write one by one.
type Dialer ¶ added in v1.6.0
type Dialer struct {
// ErrorLog is a logger that errors from packet decoding are logged to. It may be set to a logger that
// simply discards the messages.
ErrorLog *log.Logger
}
Dialer allows dialing a RakNet connection with specific configuration, such as the protocol version of the connection and the logger used.
func (Dialer) Dial ¶ added in v1.6.0
Dial attempts to dial a RakNet connection to the address passed. The address may be either an IP address or a hostname, combined with a port that is separated with ':'. Dial will attempt to dial a connection within 10 seconds. If not all packets are received after that, the connection will timeout and an error will be returned. Dial will fill out any values left as their empty values with the default values of those fields.
func (Dialer) Ping ¶ added in v1.6.0
Ping sends a ping to an address and returns the response obtained. If successful, a non-nil response byte slice containing the data is returned. If the ping failed, an error is returned describing the failure. Note that the packet sent to the server may be lost due to the nature of UDP. If this is the case, an error is returned which implies a timeout occurred.
type Listener ¶
type Listener struct {
// ErrorLog is a logger that errors from packet decoding are logged to. It may be set to a logger that
// simply discards the messages.
ErrorLog *log.Logger
// contains filtered or unexported fields
}
Listener implements a RakNet connection listener. It follows the same methods as those implemented by the TCPListener in the net package. Listener implements the net.Listener interface.
func Listen ¶
Listen listens on the address passed and returns a listener that may be used to accept connections. If not successful, an error is returned. The address follows the same rules as those defined in the net.TCPListen() function. Specific features of the listener may be modified once it is returned, such as the used ErrorLog and/or the accepted protocol.
func (*Listener) Accept ¶
Accept blocks until a connection can be accepted by the listener. If successful, Accept returns a connection that is ready to send and receive data. If not successful, a nil listener is returned and an error describing the problem.
func (*Listener) Addr ¶ added in v1.0.0
Addr returns the address the Listener is bound to and listening for connections on.
func (*Listener) Close ¶
Close closes the listener so that it may be cleaned up. It makes sure the goroutine handling incoming packets is able to be freed.
func (*Listener) HijackPong ¶
HijackPong hijacks the pong response from a server at an address passed. The listener passed will continuously update its pong data by hijacking the pong data of the server at the address. The hijack will last until the listener is shut down. If the address passed could not be resolved, an error is returned. Calling HijackPong means that any current and future pong data set using listener.PongData is overwritten each update.
func (*Listener) ID ¶ added in v1.3.0
ID returns the unique ID of the listener. This ID is usually used by a client to identify a specific server during a single session.