httpu

package
v1.4.18 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2016 License: GPL-3.0, BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxMessageBytes = 2048
)

Variables

This section is empty.

Functions

func Serve

func Serve(l net.PacketConn, handler Handler) error

Serve messages received on the given packet listener to the given handler.

Types

type HTTPUClient

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

HTTPUClient is a client for dealing with HTTPU (HTTP over UDP). Its typical function is for HTTPMU, and particularly SSDP.

func NewHTTPUClient

func NewHTTPUClient() (*HTTPUClient, error)

NewHTTPUClient creates a new HTTPUClient, opening up a new UDP socket for the purpose.

func (*HTTPUClient) Close

func (httpu *HTTPUClient) Close() error

Close shuts down the client. The client will no longer be useful following this.

func (*HTTPUClient) Do

func (httpu *HTTPUClient) Do(req *http.Request, timeout time.Duration, numSends int) ([]*http.Response, error)

Do performs a request. The timeout is how long to wait for before returning the responses that were received. An error is only returned for failing to send the request. Failures in receipt simply do not add to the resulting responses.

Note that at present only one concurrent connection will happen per HTTPUClient.

type Handler

type Handler interface {
	// ServeMessage is called for each HTTPU message received. peerAddr contains
	// the address that the message was received from.
	ServeMessage(r *http.Request)
}

Handler is the interface by which received HTTPU messages are passed to handling code.

type HandlerFunc

type HandlerFunc func(r *http.Request)

HandlerFunc is a function-to-Handler adapter.

func (HandlerFunc) ServeMessage

func (f HandlerFunc) ServeMessage(r *http.Request)

type Server

type Server struct {
	Addr            string         // UDP address to listen on
	Multicast       bool           // Should listen for multicast?
	Interface       *net.Interface // Network interface to listen on for multicast, nil for default multicast interface
	Handler         Handler        // handler to invoke
	MaxMessageBytes int            // maximum number of bytes to read from a packet, DefaultMaxMessageBytes if 0
}

A Server defines parameters for running an HTTPU server.

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() error

ListenAndServe listens on the UDP network address srv.Addr. If srv.Multicast is true, then a multicast UDP listener will be used on srv.Interface (or default interface if nil).

func (*Server) Serve

func (srv *Server) Serve(l net.PacketConn) error

Serve messages received on the given packet listener to the srv.Handler.

Jump to

Keyboard shortcuts

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