tcpsock

package module
v0.0.0-...-520f2b6 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2018 License: BSD-2-Clause Imports: 5 Imported by: 0

README

tcpsock

Package tcpsock provides easy to use interfaces for TCP I/O.

How to use

server:

server := tcpsock.NewTcpServer(listenPort, acceptTimeout, onConnConnect, onConnClose, onProtocol)
go server.Serve()
<-shutdown
server.Close()

client:

client := tcpsock.NewTcpClient(ServerAddr, onConnect, onClose, onProtocol)
go client.Run()
<-shutdown
client.Close()

There're more detailed demos which use custom binary protocols, like:

Documentation

Overview

tcpsock document

Package tcpsock provides easy to use interfaces for TCP I/O. Thanks to darksword(gansidui) and AlexStocks for their valuable projects which are gotcp(https://github.com/gansidui/gotcp) and getty(https://github.com/AlexStocks/getty).

Index

Constants

View Source
const (
	RecvBufLenMax = 4 * 1024
	SendBufLenMax = 4 * 1024

	SendBufCapMax = 10
	RecvBufCapMax = 10
)

Variables

This section is empty.

Functions

This section is empty.

Types

type OnTcpConnCallback

type OnTcpConnCallback func(c *TcpConn)

type OnTcpCustomProtocol

type OnTcpCustomProtocol func() Protocol

type Packet

type Packet interface {
	Marshal() []byte
}

type Protocol

type Protocol interface {
	Parse(b []byte, recvChan chan<- Packet)
	Process(conn *TcpConn, p Packet)
}

type TcpClient

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

func NewTcpClient

func NewTcpClient(svrAddr string, onConnConnect, onConnClose OnTcpConnCallback, onCustomProtocol OnTcpCustomProtocol) *TcpClient

func (*TcpClient) Close

func (self *TcpClient) Close()

func (*TcpClient) Run

func (self *TcpClient) Run()

type TcpConn

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

func (*TcpConn) Close

func (self *TcpConn) Close()

func (*TcpConn) Closed

func (self *TcpConn) Closed() bool

func (*TcpConn) ID

func (self *TcpConn) ID() uint32

func (*TcpConn) RawConn

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

func (*TcpConn) Write

func (self *TcpConn) Write(p Packet)

type TcpServer

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

func NewTcpServer

func NewTcpServer(listenPort, acceptTimeout int, onConnConnect, onConnClose OnTcpConnCallback, onCustomProtocol OnTcpCustomProtocol) *TcpServer

func (*TcpServer) Close

func (self *TcpServer) Close()

func (*TcpServer) NumOfConn

func (self *TcpServer) NumOfConn() uint32

func (*TcpServer) Serve

func (self *TcpServer) Serve()

Directories

Path Synopsis
samples

Jump to

Keyboard shortcuts

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