gowebsocket

package module
v0.0.0-...-6933580 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2021 License: MIT Imports: 5 Imported by: 3

README

gowebsocket

It is a fork from "github.com/fjukstad/gographer"

Simple server (and client) handling communication over web sockets. Messages are broadcasted over websockets.

How to use it

  • First start up a server:
ip := "localhost"
port := "3999"
server := gowebsocket.New(ip, port)
server.Start() 
  • Any client can connect to it by
c := gowebsocket.NewClient(ip,port) 
  • Messages can be sent/received by using .Send() and .Receive() methods:

c.Send("Hello there\n")
recv := c.Receive()
fmt.Println("Received: ", recv)

See test/websocket-test.go for more info!

Credit

Implementation is heavily based on http://gary.beagledreams.com/page/go-websocket-chat.html.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Conn     *websocket.Conn
	Listener net.Listener
}

func NewClient

func NewClient(ip, port string) (c *Client, err error)

func (*Client) Receive

func (c *Client) Receive() string

func (*Client) Send

func (c *Client) Send(message string)

func (*Client) SendBytes

func (c *Client) SendBytes(message []byte)

type WSConnHandler

type WSConnHandler interface {
	Handler(conn *websocket.Conn)
}

type WSServer

type WSServer struct {
	Hub         *hub
	Server      *http.Server
	Conn        *connection
	ConnHandler WSConnHandler
}

func New

func New(ip, port string) (s *WSServer)

func (*WSServer) GetServerInfo

func (s *WSServer) GetServerInfo() string

func (*WSServer) SetConnectionHandler

func (s *WSServer) SetConnectionHandler(connHandler WSConnHandler)

connHandler is an optional connection handler that may be registered * to receive new connections before they are attached to the hub. * Can be nil if no connection handler is desired.

func (*WSServer) Start

func (s *WSServer) Start()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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