tcpsock

package module
v0.0.0-...-badc9a6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2019 License: BSD-2-Clause Imports: 7 Imported by: 0

README

tcpsock.v2

Package tcpsock provides easy to use interfaces for TCP I/O, it's designed especially for developing online game servers.

Examples

there's a chatroom demo which uses custom binary protocol

run chatroom server on a Aliyun VPS(CentOS 7.4) which has 2 CPUs of Intel(R) Xeon(R) E5-2682 v4 @ 2.50GHz, then make 1K connections by using robot(robot.exe -s=ip:port -n=100 -r=0[1,..9]), so there are 10 rooms and each has 100 users connected. Every robot will send some words to chat server during 5~10secs.

PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
5156 root      20   0   76848  62636   1196 S  46.0  0.8   0:55.71 ./server

image


image

Documentation

Overview

Package tcpsock provides easy to use interfaces for TCP I/O. It's designed especially for developing online games.

Index

Constants

View Source
const (
	RecvBufLenMax = 16 * 1024
	SendBufLenMax = 24 * 1024
	TcpBufLenMax  = 16 * 1024
)
View Source
const (
	NumOfConnMax = 10000
)
View Source
const (
	TcpDialTimeoutInSecs = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type OnCheckIP

type OnCheckIP = func(ip net.Addr) bool

type OnTcpClose

type OnTcpClose = func() error

type OnTcpConnect

type OnTcpConnect = func(conn *TcpConn) TcpSession

type OnTcpDisconnect

type OnTcpDisconnect = func(conn *TcpConn)

type OnTcpError

type OnTcpError = func(conn *TcpConn, err error)

type OnTcpIterate

type OnTcpIterate = func(id uint64, session TcpSession)

type OnTcpWrite

type OnTcpWrite = func(b []byte) (n int, err error)

type TcpClient

type TcpClient struct {
	*TcpConn
	// contains filtered or unexported fields
}

func NewTcpClient

func NewTcpClient(svrAddr string, onConnect OnTcpConnect, onDisconnect OnTcpDisconnect) *TcpClient

func (*TcpClient) Close

func (self *TcpClient) Close() error

func (*TcpClient) Open

func (self *TcpClient) Open()

type TcpConn

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

func (*TcpConn) Close

func (self *TcpConn) Close() error

func (*TcpConn) ID

func (self *TcpConn) ID() uint64

func (*TcpConn) RawConn

func (self *TcpConn) RawConn() net.Conn

func (*TcpConn) Write

func (self *TcpConn) Write(b []byte) (n int, err error)

type TcpServer

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

func NewTcpServer

func NewTcpServer(addr string, onConnect OnTcpConnect, onDisconnect OnTcpDisconnect, onCheckIP OnCheckIP) *TcpServer

func (*TcpServer) Close

func (self *TcpServer) Close()

func (*TcpServer) Count

func (self *TcpServer) Count() uint32

func (*TcpServer) GetSession

func (self *TcpServer) GetSession(id uint64) TcpSession

func (*TcpServer) Iterate

func (self *TcpServer) Iterate(fn OnTcpIterate)

func (*TcpServer) Kick

func (self *TcpServer) Kick(id uint64)

func (*TcpServer) Send

func (self *TcpServer) Send(id uint64, b []byte)

func (*TcpServer) Serve

func (self *TcpServer) Serve()

type TcpSession

type TcpSession interface {
	SockHandle() uint64
	io.ReadWriteCloser
}

to do

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL