goworld: github.com/xiaonanln/goworld/engine/netutil Index | Files | Directories

package netutil

import "github.com/xiaonanln/goworld/engine/netutil"

Index

Package Files

BufferedConnection.go Connection.go GobMsgPacker.go JSONMsgPacker.go JsoniterMsgPacker.go MessagePackMsgPacker.go MsgPacker.go Packet.go PacketConnection.go TCPServer.go WebSocketConnection.go netutil.go

Variables

var (
    // NETWORK_ENDIAN is the network Endian of connections
    NETWORK_ENDIAN = binary.LittleEndian
)

func ConnectTCP Uses

func ConnectTCP(host string, port int) (net.Conn, error)

ConnectTCP connects to host:port in TCP

func IsConnectionError Uses

func IsConnectionError(_err interface{}) bool

IsConnectionError check if the error is a connection error (close)

func PackFloat32 Uses

func PackFloat32(order binary.ByteOrder, b []byte, f float32)

PackFloat32 packs float32 in specified byte order

func PutFloat32 Uses

func PutFloat32(b []byte, f float32)

func ServeTCP Uses

func ServeTCP(listenAddr string, delegate TCPServerDelegate) error

ServeTCP serves on specified address as TCP server

func ServeTCPForever Uses

func ServeTCPForever(listenAddr string, delegate TCPServerDelegate)

ServeTCPForever serves on specified address as TCP server, for ever ...

func UnpackFloat32 Uses

func UnpackFloat32(order binary.ByteOrder, b []byte) (f float32)

UnpackFloat32 unpacks float32 in specified byte order

type BufferedConnection Uses

type BufferedConnection struct {
    Connection
    // contains filtered or unexported fields
}

BufferedConnection provides buffered write to connections

func NewBufferedConnection Uses

func NewBufferedConnection(conn Connection) *BufferedConnection

NewBufferedWriteConnection creates a new connection with buffered write based on underlying connection

func (*BufferedConnection) Flush Uses

func (brc *BufferedConnection) Flush() error

func (*BufferedConnection) Read Uses

func (brc *BufferedConnection) Read(p []byte) (int, error)

Read

func (*BufferedConnection) Write Uses

func (brc *BufferedConnection) Write(p []byte) (int, error)

type Connection Uses

type Connection interface {
    net.Conn // Connection is more than net.Conn
    Flush() error
}

Connection interface for connections to servers

type GobMsgPacker Uses

type GobMsgPacker struct{}

GobMsgPacker packs and unpacks message in golang's Gob format

func (GobMsgPacker) PackMsg Uses

func (mp GobMsgPacker) PackMsg(msg interface{}, buf []byte) ([]byte, error)

PackMsg packs a message to bytes of gob format

func (GobMsgPacker) UnpackMsg Uses

func (mp GobMsgPacker) UnpackMsg(data []byte, msg interface{}) error

UnpackMsg unpacks bytes of gob format to message

type JSONMsgPacker Uses

type JSONMsgPacker struct{}

JsoniterMsgPacker packs and unpacks messages in JSON format

func (JSONMsgPacker) PackMsg Uses

func (mp JSONMsgPacker) PackMsg(msg interface{}, buf []byte) ([]byte, error)

PackMsg packs message to bytes of JSON format

func (JSONMsgPacker) UnpackMsg Uses

func (mp JSONMsgPacker) UnpackMsg(data []byte, msg interface{}) error

UnpackMsg unpacks bytes of JSON format to message

type JsoniterMsgPacker Uses

type JsoniterMsgPacker struct{}

JsoniterMsgPacker packs and unpacks messages in JSON format

func (JsoniterMsgPacker) PackMsg Uses

func (mp JsoniterMsgPacker) PackMsg(msg interface{}, buf []byte) ([]byte, error)

PackMsg packs message to bytes of JSON format

func (JsoniterMsgPacker) UnpackMsg Uses

func (mp JsoniterMsgPacker) UnpackMsg(data []byte, msg interface{}) error

UnpackMsg unpacks bytes of JSON format to message

type MessagePackMsgPacker Uses

type MessagePackMsgPacker struct{}

MessagePackMsgPacker packs and unpacks message in MessagePack format

func (MessagePackMsgPacker) PackMsg Uses

func (mp MessagePackMsgPacker) PackMsg(msg interface{}, buf []byte) ([]byte, error)

PackMsg packs message to bytes in MessagePack format

func (MessagePackMsgPacker) UnpackMsg Uses

func (mp MessagePackMsgPacker) UnpackMsg(data []byte, msg interface{}) error

UnpackMsg unpacksbytes in MessagePack format to message

type MsgPacker Uses

type MsgPacker interface {
    PackMsg(msg interface{}, buf []byte) ([]byte, error)
    UnpackMsg(data []byte, msg interface{}) error
}

MsgPacker is used to packs and unpacks messages

var (
    // MSG_PACKER is used for packing and unpacking network data
    MSG_PACKER MsgPacker = MessagePackMsgPacker{}
)

type NetConnection Uses

type NetConnection struct {
    net.Conn
}

NetConnection converts net.Conn to Connection

func (NetConnection) Flush Uses

func (c NetConnection) Flush() error

Flush flushes network connection

type Packet Uses

type Packet struct {
    // contains filtered or unexported fields
}

Packet is a packet for sending data

func NewPacket Uses

func NewPacket() *Packet

NewPacket allocates a new packet

func (*Packet) AddRefCount Uses

func (p *Packet) AddRefCount(add int64)

AddRefCount adds reference count of packet

func (*Packet) AppendArgs Uses

func (p *Packet) AppendArgs(args []interface{})

AppendArgs appends arguments to the end of payload one by one

func (*Packet) AppendBool Uses

func (p *Packet) AppendBool(b bool)

AppendBool appends one byte 1/0 to the end of payload

func (*Packet) AppendByte Uses

func (p *Packet) AppendByte(b byte)

AppendByte appends one byte to the end of payload

func (*Packet) AppendBytes Uses

func (p *Packet) AppendBytes(v []byte)

AppendBytes appends slice of bytes to the end of payload

func (*Packet) AppendClientID Uses

func (p *Packet) AppendClientID(id common.ClientID)

AppendClientID appends one Client ID to the end of payload

func (*Packet) AppendData Uses

func (p *Packet) AppendData(msg interface{})

AppendData appends one data of any type to the end of payload

func (*Packet) AppendEntityID Uses

func (p *Packet) AppendEntityID(id common.EntityID)

AppendEntityID appends one Entity ID to the end of payload

func (*Packet) AppendFloat32 Uses

func (p *Packet) AppendFloat32(f float32)

AppendFloat32 appends one float32 to the end of payload

func (*Packet) AppendFloat64 Uses

func (p *Packet) AppendFloat64(f float64)

AppendFloat64 appends one float64 to the end of payload

func (*Packet) AppendStringList Uses

func (p *Packet) AppendStringList(list []string)

AppendStringList appends a list of strings to the end of payload

func (*Packet) AppendUint16 Uses

func (p *Packet) AppendUint16(v uint16)

AppendUint16 appends one uint16 to the end of payload

func (*Packet) AppendUint32 Uses

func (p *Packet) AppendUint32(v uint32)

AppendUint32 appends one uint32 to the end of payload

func (*Packet) AppendUint64 Uses

func (p *Packet) AppendUint64(v uint64)

AppendUint64 appends one uint64 to the end of payload

func (*Packet) AppendVarBytes Uses

func (p *Packet) AppendVarBytes(v []byte)

AppendVarBytes appends varsize bytes to the end of payload

func (*Packet) AppendVarStr Uses

func (p *Packet) AppendVarStr(s string)

AppendVarStr appends a varsize string to the end of payload

func (*Packet) AssureCapacity Uses

func (p *Packet) AssureCapacity(need uint32)

func (*Packet) ClearPayload Uses

func (p *Packet) ClearPayload()

ClearPayload clears packet payload

func (*Packet) GetPayloadLen Uses

func (p *Packet) GetPayloadLen() uint32

GetPayloadLen returns the payload length

func (*Packet) HasUnreadPayload Uses

func (p *Packet) HasUnreadPayload() bool

HasUnreadPayload returns if all payload is read

func (*Packet) Payload Uses

func (p *Packet) Payload() []byte

Payload returns the total payload of packet

func (*Packet) PayloadCap Uses

func (p *Packet) PayloadCap() uint32

PayloadCap returns the current payload capacity

func (*Packet) PopUint32 Uses

func (p *Packet) PopUint32() (v uint32)

PopUint32 pops one uint32 from the end of payload

func (*Packet) ReadArgs Uses

func (p *Packet) ReadArgs() [][]byte

ReadArgs reads a number of arguments from the beginning of unread payload

func (*Packet) ReadBool Uses

func (p *Packet) ReadBool() (v bool)

ReadBool reads one byte 1/0 from the beginning of unread payload

func (*Packet) ReadBytes Uses

func (p *Packet) ReadBytes(size uint32) []byte

ReadBytes reads bytes from the beginning of unread payload

func (*Packet) ReadClientID Uses

func (p *Packet) ReadClientID() common.ClientID

ReadClientID reads one ClientID from the beginning of unread payload

func (*Packet) ReadData Uses

func (p *Packet) ReadData(msg interface{})

ReadData reads one data of any type from the beginning of unread payload

func (*Packet) ReadEntityID Uses

func (p *Packet) ReadEntityID() common.EntityID

ReadEntityID reads one EntityID from the beginning of unread payload

func (*Packet) ReadFloat32 Uses

func (p *Packet) ReadFloat32() float32

ReadFloat32 reads one float32 from the beginning of unread payload

func (*Packet) ReadFloat64 Uses

func (p *Packet) ReadFloat64() float64

ReadFloat64 reads one float64 from the beginning of unread payload

func (*Packet) ReadOneByte Uses

func (p *Packet) ReadOneByte() (v byte)

ReadOneByte reads one byte from the beginning

func (*Packet) ReadStringList Uses

func (p *Packet) ReadStringList() []string

ReadStringList reads a list of strings from the beginning of unread payload

func (*Packet) ReadUint16 Uses

func (p *Packet) ReadUint16() (v uint16)

ReadUint16 reads one uint16 from the beginning of unread payload

func (*Packet) ReadUint32 Uses

func (p *Packet) ReadUint32() (v uint32)

ReadUint32 reads one uint32 from the beginning of unread payload

func (*Packet) ReadUint64 Uses

func (p *Packet) ReadUint64() (v uint64)

ReadUint64 reads one uint64 from the beginning of unread payload

func (*Packet) ReadVarBytes Uses

func (p *Packet) ReadVarBytes() []byte

ReadVarBytes reads a varsize slice of bytes from the beginning of unread payload

func (*Packet) ReadVarStr Uses

func (p *Packet) ReadVarStr() string

ReadVarStr reads a varsize string from the beginning of unread payload

func (*Packet) Release Uses

func (p *Packet) Release()

Release releases the packet to packet pool

func (*Packet) SetNotCompress Uses

func (p *Packet) SetNotCompress()

SetNotCompress force the packet not to be compressed

func (*Packet) SetPayloadLen Uses

func (p *Packet) SetPayloadLen(plen uint32)

SetPayloadLen sets the payload l

func (*Packet) TotalPayload Uses

func (p *Packet) TotalPayload() []byte

func (*Packet) UnreadPayload Uses

func (p *Packet) UnreadPayload() []byte

UnreadPayload returns the unread payload

func (*Packet) UnwrittenPayload Uses

func (p *Packet) UnwrittenPayload() []byte

UnwrittenPayload returns the unwritten payload, which is the left payload capacity

type PacketConnection Uses

type PacketConnection struct {
    // contains filtered or unexported fields
}

PacketConnection is a connection that send and receive data packets upon a network stream connection

func NewPacketConnection Uses

func NewPacketConnection(conn Connection, compressor compress.Compressor) *PacketConnection

NewPacketConnection creates a packet connection based on network connection

func (*PacketConnection) Close Uses

func (pc *PacketConnection) Close() error

Close the connection

func (*PacketConnection) Flush Uses

func (pc *PacketConnection) Flush(reason string) (err error)

Flush connection writes

func (*PacketConnection) LocalAddr Uses

func (pc *PacketConnection) LocalAddr() net.Addr

LocalAddr returns the local address

func (*PacketConnection) NewPacket Uses

func (pc *PacketConnection) NewPacket() *Packet

NewPacket allocates a new packet (usually for sending)

func (*PacketConnection) RecvPacket Uses

func (pc *PacketConnection) RecvPacket() (*Packet, error)

RecvPacket receives the next packet

func (*PacketConnection) RemoteAddr Uses

func (pc *PacketConnection) RemoteAddr() net.Addr

RemoteAddr return the remote address

func (*PacketConnection) SendPacket Uses

func (pc *PacketConnection) SendPacket(packet *Packet) error

SendPacket send packets to remote

func (*PacketConnection) SetRecvDeadline Uses

func (pc *PacketConnection) SetRecvDeadline(deadline time.Time) error

SetRecvDeadline sets the receive deadline

func (*PacketConnection) String Uses

func (pc *PacketConnection) String() string

type TCPServerDelegate Uses

type TCPServerDelegate interface {
    ServeTCPConnection(net.Conn)
}

TCPServerDelegate is the implementations that a TCP server should provide

Directories

PathSynopsis
compress

Package netutil imports 21 packages (graph) and is imported by 8 packages. Updated 2017-11-06. Refresh now. Tools for package owners.