Documentation ¶
Overview ¶
networking provides all network abstractions : connection read and write, parsing some data types, errors, etc...
Index ¶
- Constants
- Variables
- type Conn
- type DialTCPOptions
- type DialUDPOptions
- type Input
- func (in *Input) Read(buf []byte) (int, error)
- func (in *Input) ReadBigEndianInt16() (uint16, error)
- func (in *Input) ReadBigEndianInt32() (uint32, error)
- func (in *Input) ReadBigEndianInt64() (uint64, error)
- func (in *Input) ReadByte() (byte, error)
- func (in *Input) ReadBytes(n int) ([]byte, error)
- func (in *Input) ReadLittleEndianInt16() (uint16, error)
- func (in *Input) ReadLittleEndianInt32() (uint32, error)
- func (in *Input) ReadLittleEndianInt64() (uint64, error)
- func (in *Input) ReadNullTerminatedString() (string, error)
- func (in *Input) ReadRaknetString() (string, error)
- func (in *Input) ReadString() (string, error)
- func (in *Input) ReadUVarInt() (uint64, error)
- func (in *Input) ReadVarInt() (int64, error)
- type Output
- func (out *Output) Bytes() []byte
- func (out *Output) Write(buf []byte) (int, error)
- func (out *Output) WriteBigEndianInt16(i uint16)
- func (out *Output) WriteBigEndianInt32(i uint32)
- func (out *Output) WriteBigEndianInt64(i uint64)
- func (out *Output) WriteByte(b byte) error
- func (out *Output) WriteBytes(b []byte)
- func (out *Output) WriteLittleEndianInt16(i uint16)
- func (out *Output) WriteLittleEndianInt32(i uint32)
- func (out *Output) WriteLittleEndianInt64(i uint64)
- func (out *Output) WriteNullTerminatedString(s string)
- func (out *Output) WriteRaknetString(s string)
- func (out *Output) WriteSingleByte(b byte)
- func (out *Output) WriteString(s string)
- func (out *Output) WriteUVarInt(i uint64)
- func (out *Output) WriteVarInt(i int64)
- type TCPConn
- type UDPConn
Constants ¶
const (
MaximumUDPDatagramLength int = 65535
)
Variables ¶
var ( ErrConnectionNotEstablished error = errors.New("connection hasn't been established yet. Call Connect method to establish connection") ErrConnectionAlreadyEstablished error = errors.New("connection has already been established. If you want to reopen a connection for this client, you have to call Disconnect first") )
Usual networking errors common to clients
Functions ¶
This section is empty.
Types ¶
type DialTCPOptions ¶
DialTCPOptions are the options for the DialTCP function. An empty struct (all fields set to false) is considered as the default behavior for the DialTCP function.
type DialUDPOptions ¶
type DialUDPOptions struct { SkipSRVLookup bool ForceUDPProtocolForSRVLookup bool DialTimeout time.Duration }
DialUDPOptions are the options for the DialUDP function. An empty struct (all fields set to false) is considered as the default behavior for the DialUDP function.
type Input ¶
type Input struct {
// contains filtered or unexported fields
}
Input represents a connection input (i.e. what's read from the connection). It wraps several helpers to read from this input.
func (*Input) Read ¶
Read is just a wrapper around internal reader to make Input implements io.Reader.
func (*Input) ReadBigEndianInt16 ¶
ReadBigEndianInt16 tries to read a big endian 2-bytes int (short) from the input.
func (*Input) ReadBigEndianInt32 ¶
ReadBigEndianInt32 tries to read a big endian 4-bytes int from the input.
func (*Input) ReadBigEndianInt64 ¶
ReadBigEndianInt64 tries to read a big endian 8-bytes int (long) from the input.
func (*Input) ReadByte ¶
ReadByte tries to read a single byte from the input. RedByte also implements io.ByteReader interface, which is useful to use binary.ReadUvarint on the Input itself (see method ReadUVarInt).
func (*Input) ReadLittleEndianInt16 ¶
ReadLittleEndianInt16 tries to read a little endian 2-bytes int (short) from the input.
func (*Input) ReadLittleEndianInt32 ¶
ReadLittleEndianInt32 tries to read a little endian 4-bytes int from the input.
func (*Input) ReadLittleEndianInt64 ¶
ReadLittleEndianInt64 tries to read a little endian 8-bytes int (long) from the input.
func (*Input) ReadNullTerminatedString ¶
ReadNullTerminatedString tries to read a null terminated string from the input.
func (*Input) ReadRaknetString ¶ added in v1.3.0
ReadRaknetString tries to read a raknet string from the input. It is a UTF-8 string prefixed with its size in bytes as a big endian unsigned short.
func (*Input) ReadString ¶
ReadString tries to read a standard minecraft protocol string from the input. It is a UTF-8 string prefixed with its size in bytes as an unsigned varint.
func (*Input) ReadUVarInt ¶
ReadUVarInt64 tries to read an unsigned varint from the input.
func (*Input) ReadVarInt ¶
ReadVarInt64 tries to read a signed varint from the input.
type Output ¶
type Output struct {
// contains filtered or unexported fields
}
Output represents a connection output (i.e. what's written to the connection). It wraps several helpers to write to this output.
func MergeOutputs ¶
MergeOutputs merge buffers of two outputs, creating a new output and without modifying any of the merged output buffer.
func (*Output) Write ¶
Write is just a wrapper around WriteBytes to make Request implement io.Writer
func (*Output) WriteBigEndianInt16 ¶
WriteBigEndianInt16 writes a big endian 2-bytes int (short) to the output.
func (*Output) WriteBigEndianInt32 ¶
WriteBigEndianInt32 writes a big endian 4-bytes int to the output.
func (*Output) WriteBigEndianInt64 ¶
WriteBigEndianInt64 writes a big endian 8-bytes int (long) to the output.
func (*Output) WriteByte ¶
WriteByte is equivalent to WriteSingleByte but implements io.ByteWriter interface
func (*Output) WriteBytes ¶
WriteBytes writes a slice of bytes to the output.
func (*Output) WriteLittleEndianInt16 ¶
WriteLittleEndianInt16 writes a little endian 2-bytes int (short) to the output.
func (*Output) WriteLittleEndianInt32 ¶
WriteLittleEndianInt32 writes a little endian 4-bytes int to the output.
func (*Output) WriteLittleEndianInt64 ¶
WriteLittleEndianInt64 writes a little endian 8-bytes int (long) to the output.
func (*Output) WriteNullTerminatedString ¶
WriteNullTerminatedString writes a null terminated string the the output.
func (*Output) WriteRaknetString ¶ added in v1.3.0
WriteRaknetString writes a raknet string to the output. It is a UTF-8 string prefixed with its size in bytes as a big endian unsigned short.
func (*Output) WriteSingleByte ¶
WriteSingleByte writes a single byte to the output.
func (*Output) WriteString ¶
WriteString writes a standard minecraft protocol string to the output. It is a UTF-8 string prefixed with its size in bytes as an unsigned varint.
func (*Output) WriteUVarInt ¶
WriteUVarInt64 writes an unsigned varint to the output.
func (*Output) WriteVarInt ¶
WriteVarInt64 writes a signed varint to the output.
type TCPConn ¶
type TCPConn struct {
// contains filtered or unexported fields
}
TCPConn is a tcp connection.
func DialTCP ¶
func DialTCP(hostname string, port int, options DialTCPOptions) (*TCPConn, error)
DialTCP resolve TCP address and connects to the address using TCP.
type UDPConn ¶
type UDPConn struct {
// contains filtered or unexported fields
}
UDPConn is a udp connection.
func DialUDP ¶
func DialUDP(hostname string, port int, options DialUDPOptions) (*UDPConn, error)
DialTCP resolve UDP address and connects to the address using UDP.
func (UDPConn) Send ¶
Send sends output to the connection, waits for response and returns the connection input. For UDP connections, as they cannot be read in multiple time, the connection is read a single time and loaded into a buffer of size MaximumUDPDatagramLength. UDP datagram length should not be over MaximumUDPDatagramLength, so the entire datagram should be loaded. A *bytes.Buffer is the passed as the reader for the response.