Documentation
¶
Index ¶
- Constants
- func ErrConnectionClosed(err error) bool
- func ErrReadTimeout(err error) bool
- func Ping(address string, settings ...Setting) (response []byte, err error)
- type Conn
- func (conn *Conn) Close() error
- func (conn *Conn) Latency() int
- 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(t time.Time) error
- func (conn *Conn) Write(b []byte) (n int, err error)
- type Listener
- type Setting
Constants ¶
const ( // MinecraftProtocol is the current default Minecraft RakNet protocol version. This is Minecraft specific. // For the default RakNet, use OfficialProtocol. // MinecraftProtocol is the default in go-raknet. MinecraftProtocol byte = 9 // OfficialProtocol is the protocol version of the official open source RakNet library. OfficialProtocol byte = 6 )
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.
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.
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. Optionally, a variadic amount of settings may be passed into Dial to specify additional behaviour.
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 the last measured latency between both ends of the connection in milliseconds. The latency is updated every 4 seconds. The latency returned is the time it takes to send one packet from one end to the other end of the connection. It is not the round-trip time.
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 Listener ¶
type Listener struct {
// 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.
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.
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) 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. A list of settings may be passed in to specify additional settings such as the protocol version for the ping/pong.