{"modulePath":"code.cloudfoundry.org/cli","version":"v6.1.1+incompatible","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package websocket\n\nPackage websocket implements a client and server for the WebSocket protocol as specified in RFC 6455.\n\n## Constants\n\n```go\nconst (\n\tProtocolVersionHybi13    = 13\n\tProtocolVersionHybi      = ProtocolVersionHybi13\n\tSupportedProtocolVersion = \"13\"\n\n\tContinuationFrame = 0\n\tTextFrame         = 1\n\tBinaryFrame       = 2\n\tCloseFrame        = 8\n\tPingFrame         = 9\n\tPongFrame         = 10\n\tUnknownFrame      = 255\n)\n```\n\n## Variables\n\n```go\nvar (\n\tErrBadMaskingKey         = \u0026ProtocolError{\"bad masking key\"}\n\tErrBadPongMessage        = \u0026ProtocolError{\"bad pong message\"}\n\tErrBadClosingStatus      = \u0026ProtocolError{\"bad closing status\"}\n\tErrUnsupportedExtensions = \u0026ProtocolError{\"unsupported extensions\"}\n\tErrNotImplemented        = \u0026ProtocolError{\"not implemented\"}\n)\n```\n\n```go\nvar (\n\tErrBadProtocolVersion   = \u0026ProtocolError{\"bad protocol version\"}\n\tErrBadScheme            = \u0026ProtocolError{\"bad scheme\"}\n\tErrBadStatus            = \u0026ProtocolError{\"bad status\"}\n\tErrBadUpgrade           = \u0026ProtocolError{\"missing or bad upgrade\"}\n\tErrBadWebSocketOrigin   = \u0026ProtocolError{\"missing or bad WebSocket-Origin\"}\n\tErrBadWebSocketLocation = \u0026ProtocolError{\"missing or bad WebSocket-Location\"}\n\tErrBadWebSocketProtocol = \u0026ProtocolError{\"missing or bad WebSocket-Protocol\"}\n\tErrBadWebSocketVersion  = \u0026ProtocolError{\"missing or bad WebSocket Version\"}\n\tErrChallengeResponse    = \u0026ProtocolError{\"mismatch challenge/response\"}\n\tErrBadFrame             = \u0026ProtocolError{\"bad frame\"}\n\tErrBadFrameBoundary     = \u0026ProtocolError{\"not on frame boundary\"}\n\tErrNotWebSocket         = \u0026ProtocolError{\"not websocket protocol\"}\n\tErrBadRequestMethod     = \u0026ProtocolError{\"bad method\"}\n\tErrNotSupported         = \u0026ProtocolError{\"not supported\"}\n)\n```\n\n```go\nvar JSON = Codec{jsonMarshal, jsonUnmarshal}\n```\nJSON is a codec to send/receive JSON data in a frame from a WebSocket connection.\n\nTrivial usage:\n\n\timport \"websocket\"\n\n\ttype T struct {\n\t\tMsg string\n\t\tCount int\n\t}\n\n\t// receive JSON type T\n\tvar data T\n\twebsocket.JSON.Receive(ws, \u0026data)\n\n\t// send JSON type T\n\twebsocket.JSON.Send(ws, data)\n\n```go\nvar Message = Codec{marshal, unmarshal}\n```\nMessage is a codec to send/receive text/binary data in a frame on WebSocket connection. To send/receive text frame, use string type. To send/receive binary frame, use \\[]byte type.\n\nTrivial usage:\n\n\timport \"websocket\"\n\n\t// receive text frame\n\tvar message string\n\twebsocket.Message.Receive(ws, \u0026message)\n\n\t// send text frame\n\tmessage = \"hello\"\n\twebsocket.Message.Send(ws, message)\n\n\t// receive binary frame\n\tvar data []byte\n\twebsocket.Message.Receive(ws, \u0026data)\n\n\t// send binary frame\n\tdata = []byte{0, 1, 2}\n\twebsocket.Message.Send(ws, data)\n\n## Functions\n\n```go\nfunc Origin(config *Config, req *http.Request) (*url.URL, error)\n```\nOrigin parses Origin header in \"req\". If origin is \"null\", returns (nil, nil).\n\n## Types\n\n```go\ntype Addr struct {\n\t*url.URL\n}\n```\nAddr is an implementation of net.Addr for WebSocket.\n\n```go\nfunc (addr *Addr) Network() string\n```\nNetwork returns the network type for a WebSocket, \"websocket\".\n\n```go\ntype Codec struct {\n\tMarshal   func(v interface{}) (data []byte, payloadType byte, err error)\n\tUnmarshal func(data []byte, payloadType byte, v interface{}) (err error)\n}\n```\nCodec represents a symmetric pair of functions that implement a codec.\n\n```go\nfunc (cd Codec) Receive(ws *Conn, v interface{}) (err error)\n```\nReceive receives single frame from ws, unmarshaled by cd.Unmarshal and stores in v.\n\n```go\nfunc (cd Codec) Send(ws *Conn, v interface{}) (err error)\n```\nSend sends v marshaled by cd.Marshal as single frame to ws.\n\n```go\ntype Config struct {\n\t// A WebSocket server address.\n\tLocation *url.URL\n\n\t// A Websocket client origin.\n\tOrigin *url.URL\n\n\t// WebSocket subprotocols.\n\tProtocol []string\n\n\t// WebSocket protocol version.\n\tVersion int\n\n\t// TLS config for secure WebSocket (wss).\n\tTlsConfig *tls.Config\n\n\t// Additional header fields to be sent in WebSocket opening handshake.\n\tHeader http.Header\n\t// contains filtered or unexported fields\n}\n```\nConfig is a WebSocket configuration\n\n```go\nfunc NewConfig(server, origin string) (config *Config, err error)\n```\nNewConfig creates a new WebSocket config for client connection.\n\n```go\ntype Conn struct {\n\tPayloadType byte\n\t// contains filtered or unexported fields\n}\n```\nConn represents a WebSocket connection.\n\n```go\nfunc Dial(url_, protocol, origin string) (ws *Conn, err error)\n```\nDial opens a new client connection to a WebSocket.\n\n```go\nfunc DialConfig(config *Config) (ws *Conn, err error)\n```\nDialConfig opens a new client connection to a WebSocket with a config.\n\n```go\nfunc NewClient(config *Config, rwc io.ReadWriteCloser) (ws *Conn, err error)\n```\nNewClient creates a new WebSocket client connection over rwc.\n\n```go\nfunc (ws *Conn) Close() error\n```\nClose implements the io.Closer interface.\n\n```go\nfunc (ws *Conn) Config() *Config\n```\nConfig returns the WebSocket config.\n\n```go\nfunc (ws *Conn) IsClientConn() bool\n```\n\n```go\nfunc (ws *Conn) IsServerConn() bool\n```\n\n```go\nfunc (ws *Conn) LocalAddr() net.Addr\n```\nLocalAddr returns the WebSocket Origin for the connection for client, or the WebSocket location for server.\n\n```go\nfunc (ws *Conn) Read(msg []byte) (n int, err error)\n```\nRead implements the io.Reader interface: it reads data of a frame from the WebSocket connection. if msg is not large enough for the frame data, it fills the msg and next Read will read the rest of the frame data. it reads Text frame or Binary frame.\n\n```go\nfunc (ws *Conn) RemoteAddr() net.Addr\n```\nRemoteAddr returns the WebSocket location for the connection for client, or the Websocket Origin for server.\n\n```go\nfunc (ws *Conn) Request() *http.Request\n```\nRequest returns the http request upgraded to the WebSocket. It is nil for client side.\n\n```go\nfunc (ws *Conn) SetDeadline(t time.Time) error\n```\nSetDeadline sets the connection's network read \u0026 write deadlines.\n\n```go\nfunc (ws *Conn) SetReadDeadline(t time.Time) error\n```\nSetReadDeadline sets the connection's network read deadline.\n\n```go\nfunc (ws *Conn) SetWriteDeadline(t time.Time) error\n```\nSetWriteDeadline sets the connection's network write deadline.\n\n```go\nfunc (ws *Conn) Write(msg []byte) (n int, err error)\n```\nWrite implements the io.Writer interface: it writes data as a frame to the WebSocket connection.\n\n```go\ntype DialError struct {\n\t*Config\n\tErr error\n}\n```\nDialError is an error that occurs while dialling a websocket server.\n\n```go\nfunc (e *DialError) Error() string\n```\n\n```go\ntype Handler func(*Conn)\n```\nHandler is a simple interface to a WebSocket browser client. It checks if Origin header is valid URL by default. You might want to verify websocket.Conn.Config().Origin in the func. If you use Server instead of Handler, you could call websocket.Origin and check the origin in your Handshake func. So, if you want to accept non-browser client, which doesn't send Origin header, you could use Server . that doesn't check origin in its Handshake.\n\n```go\nfunc (h Handler) ServeHTTP(w http.ResponseWriter, req *http.Request)\n```\nServeHTTP implements the http.Handler interface for a WebSocket\n\n```go\ntype ProtocolError struct {\n\tErrorString string\n}\n```\nProtocolError represents WebSocket protocol errors.\n\n```go\nfunc (err *ProtocolError) Error() string\n```\n\n```go\ntype Server struct {\n\t// Config is a WebSocket configuration for new WebSocket connection.\n\tConfig\n\n\t// Handshake is an optional function in WebSocket handshake.\n\t// For example, you can check, or don't check Origin header.\n\t// Another example, you can select config.Protocol.\n\tHandshake func(*Config, *http.Request) error\n\n\t// Handler handles a WebSocket connection.\n\tHandler\n}\n```\nServer represents a server of a WebSocket.\n\n```go\nfunc (s Server) ServeHTTP(w http.ResponseWriter, req *http.Request)\n```\nServeHTTP implements the http.Handler interface for a WebSocket\n\n","path":"code.cloudfoundry.org/cli/src/code.google.com/p/go.net/websocket","name":"websocket","synopsis":"Package websocket implements a client and server for the WebSocket protocol as specified in RFC 6455.","isRedistributable":true}
