Skip to content
This repository has been archived by the owner on Aug 27, 2021. It is now read-only.

Latest commit

 

History

History
34 lines (26 loc) · 664 Bytes

README.md

File metadata and controls

34 lines (26 loc) · 664 Bytes

Packet Stream

Simple protocol for streaming packets with a length prefix.

Usage

type Session struct {
	*pstream.Session
}

// RemoteEvent is defined as a protobuf message.

// readPump reads messages.
func (s *Session) readPump(ctx context.Context) {
	for {
		var msg RemoteEvent
		if err := s.Session.RecvMsg(&msg); err != nil {
			if err != io.EOF {
				le.WithError(err).Error("peer connection closed")
			}

			return
		}
        
        // handle msg
	}
}

subCtx, subCtxCancel := context.WithCancel(r.ctx)
pSess := pstream.NewSessionWithCompression(subCtx, subCtxCancel, stream)
sess := &Session{Session: pSess}
go sess.readPump(subCtx)