websocket

package module
v0.0.0-...-8b3688a Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2018 License: BSD-2-Clause Imports: 5 Imported by: 0

README

WebSocket

A thin wrapper of gorilla/websocket. This library just adds net.Conn interface to gorilla/websocket.Conn.

GoDoc License

Usage
package main

import (
	"log"
	"net/http"

	gorilla "github.com/gorilla/websocket"
	"github.com/ryskiwt/websocket"
)

func main() {

	var conn *websocket.Conn
	var err error

	conn, err = websocket.Dial("ws://127.0.0.1/socket", nil)
	if err != nil {
		log.Fatalf("%#v\n", err)
	}
	defer conn.Close()

	var w http.ResponseWriter
	var r *http.Request
	conn, err = websocket.WrapUpgrade(gorilla.Upgrade(w, r, nil, 1024, 1024))
	if err != nil {
		log.Fatalf("%#v\n", err)
	}
	defer conn.Close()

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	*websocket.Conn
	// contains filtered or unexported fields
}

Conn represents a WebSocket connection. It is a thin wrapper of gorilla/websocket.Conn implementing net.Conn.

func Dial

func Dial(url string, header http.Header) (ws *Conn, err error)

Dial opens a new client connection to a WebSocket.

func WrapUpgrade

func WrapUpgrade(conn *websocket.Conn, err error) (*Conn, error)

WrapUpgrade wraps gorilla/websocket.Upgrade.

func (*Conn) Close

func (ws *Conn) Close() error

Close closes connection.

func (*Conn) Read

func (ws *Conn) Read(bs []byte) (n int, err error)

Read reads data from the connection.

func (*Conn) SetDeadline

func (ws *Conn) SetDeadline(t time.Time) error

SetDeadline sets the read and write deadlines associated with the connection.

func (*Conn) Write

func (ws *Conn) Write(bs []byte) (n int, err error)

Write writes data to the connection.

Jump to

Keyboard shortcuts

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