socket

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

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

Go to latest
Published: Nov 25, 2019 License: MIT Imports: 6 Imported by: 2

README

go-multiplexingsocket

net.Conn multiplexing.

multiplexing

how to use

  1. import
import (
    socket "github.com/LiMoMoMo/go-multiplexingsocket"
)

2.get Socket use net.Conn init Socket

	socket := socket.NewSocket(cancel, ctx, conn)
  1. register Stream use number register Stream
	stream3, _ := socket.Register(3)
  1. use Stream you can use socket.Stream as io.ReadWriter

Documentation

Index

Constants

View Source
const (
	//LEN message prefix length
	LEN = 4
	//INTERVAL read step length
	INTERVAL = 1024
	//CHANNELSIZE size of channel
	CHANNELSIZE = 16
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Socket

type Socket struct {
	Closef context.CancelFunc
	Ctx    context.Context
	//
	Conn net.Conn
	// contains filtered or unexported fields
}

Socket instance

func NewSocket

func NewSocket(clf context.CancelFunc, ctx context.Context, conn net.Conn) *Socket

func (*Socket) Register

func (s *Socket) Register(streamid int) (*Stream, error)

Register stream_id & stream_handler

func (*Socket) Start

func (s *Socket) Start() error

Start running this socket

type Stream

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

Stream instance

func (*Stream) Read

func (s *Stream) Read(data []byte) (n int, err error)

Read from stream

func (*Stream) Write

func (s *Stream) Write(data []byte) (n int, err error)

Write(b []byte) (n int, err error) Write to stream

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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