udp_to_ws

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2022 License: MIT Imports: 4 Imported by: 0

README

udp_to_ws

udp_to_ws provides udp data over websocket

Usage

Connect to a UDP source
conn := ConnectUDP("localhost:20777")
Implement the handler interface

The UdpWebSocket method needs to be implemented

type socketHandlers struct {
	conn *net.UDPConn
}

func (h *socketHandlers) UdpWebSocket(c *websocket.Conn, w http.ResponseWriter, r *http.Request) {
	packetData := make([]byte, 4*10) // 10 bytes
	extraData := make([]byte, 5*10) // 5 bytes
	ReadUDP(h.conn, packetData, extraData)

	c.WriteMessage(websocket.BinaryMessage, packetData)
}
Start the server
handlers := &socketHandlers{
	conn: conn,
}
StartServer(handlers)

Documentation

Overview

Package udp_to_ws provides udp data over websocket

Usage: See Repo

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectUDP

func ConnectUDP(port string) *net.UDPConn

Creates a UDP Connection to the given port. The port is passed to net.ResolveUDPAddr to start the connection

func ReadUDP

func ReadUDP(conn *net.UDPConn, packetData []byte, extraData []byte)

Reads the data available on the UDP connection Data will be read into packet data and extra data

func StartServer

func StartServer(handlers Handlers, options ...Option)

Starts the WebSocket server with the given handler If a addr option is not specified the default port is 8080

Types

type Handlers

type Handlers interface {
	UdpWebSocket(c *websocket.Conn, w http.ResponseWriter, r *http.Request)
}

type Option

type Option func(*ServerConfig)

func WithAddr

func WithAddr(addr string) Option

func WithDefaults

func WithDefaults() Option

type ServerConfig

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

Jump to

Keyboard shortcuts

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