engineio

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2021 License: BSD-3-Clause Imports: 17 Imported by: 0

README

go-engine.io

GoDoc

go-engine.io is the implement of engine.io in golang, which is transport-based cross-browser/cross-device bi-directional communication layer for go-socket.io.

It is compatible with node.js implement, and supported long-polling and websocket transport.

Install

Install the package with:

go get github.com/googollee/go-socket.io/engineio@v1

Import it with:

import "github.com/googollee/go-socket.io/engineio"

and use engineio as the package name inside the code.

Example

Please check example folder for details.

package main

import (
	"io/ioutil"
	"log"
	"net/http"

	"github.com/googollee/go-socket.io/engineio"
)

func main() {
	server := engineio.NewServer(nil)

	go func() {
		for {
			conn, err := server.Accept()
			if err != nil {
				log.Fatalln("accept error:", err)
			}
			
			go func() {
				defer conn.Close()
				
				for {
					t, r, _ := conn.NextReader()
					b, _ := ioutil.ReadAll(r)
					r.Close()

					w, _ := conn.NextWriter(t)
					w.Write(b)
					w.Close()
				}
			}()
		}
	}()

	http.Handle("/engine.io/", server)
	log.Println("Serving at localhost:5000...")
	
	log.Fatal(http.ListenAndServe(":5000", nil))
}

License

The 3-clause BSD License - see LICENSE for more details

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckerFunc

type CheckerFunc func(*http.Request) (http.Header, error)

CheckerFunc is function to check request.

type Conn

type Conn interface {
	ID() string
	NextReader() (session.FrameType, io.ReadCloser, error)
	NextWriter(fType session.FrameType) (io.WriteCloser, error)
	Close() error
	URL() url.URL
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
	RemoteHeader() http.Header
	SetContext(v interface{})
	Context() interface{}
}

Conn is connection by client session

type ConnInitorFunc

type ConnInitorFunc func(*http.Request, Conn)

ConnInitorFunc is function to do after create connection.

type Dialer

type Dialer struct {
	Transports []transport.Transport
}

Dialer is dialer configure.

func (*Dialer) Dial

func (d *Dialer) Dial(urlStr string, requestHeader http.Header) (Conn, error)

Dial returns a connection which dials to url with requestHeader.

type Opener

type Opener interface {
	Open() (transport.ConnParameters, error)
}

Opener is client connection which need receive open message first.

type Options

type Options struct {
	PingTimeout  time.Duration
	PingInterval time.Duration

	Transports         []transport.Transport
	SessionIDGenerator session.IDGenerator

	RequestChecker CheckerFunc
	ConnInitor     ConnInitorFunc
}

Options is options to create a server.

type Pauser

type Pauser interface {
	Pause()
	Resume()
}

Pauser is connection which can be paused and resumes.

type Server

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

Server is instance of server

func NewServer

func NewServer(opts *Options) *Server

NewServer returns a server.

func (*Server) Accept

func (s *Server) Accept() (Conn, error)

Accept accepts a connection.

func (*Server) Addr

func (s *Server) Addr() net.Addr

func (*Server) Close

func (s *Server) Close() error

Close closes server.

func (*Server) Count

func (s *Server) Count() int

Count counts connected

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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