Categorygithub.com/willscott/goturn
repositorypackage
0.0.0-20170802220503-19f41278d0c9
Repository: https://github.com/willscott/goturn.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# README

Go TURN

GoDoc

This is a library providing a Go interface compatible with the golang proxy package which connects through a TURN relay.

This package provides parsing and encoding support for STUN and TURN protocols.

Installation

go get github.com/willscott/goturn

Full Example

package main

import (
	"io/ioutil"
	"log"
	"net"
	"net/http"

	"github.com/willscott/goturn/client"
)

func main() {
	// Connect to the stun/turn server
	conn, err := net.Dial("tcp", "127.0.0.1:19302")
	if err != nil {
		log.Fatal("error dialing TURN server: ", err)
	}
	defer conn.Close()

	credentials := client.LongtermCredentials("username", "password")
	dialer, err := client.NewDialer(&credentials, conn)
	if err != nil {
		log.Fatal("failed to obtain dialer: ", err)
	}

	httpClient := &http.Client{Transport: &http.Transport{Dial: dialer.Dial}}
	httpResp, err := httpClient.Get("http://www.google.com/")
	if err != nil {
		log.Fatal("error performing http request: ", err)
	}
	defer httpResp.Body.Close()

	httpBody, err := ioutil.ReadAll(httpResp.Body)
	if err != nil {
		log.Fatal("error reading http response: ", err)
	}
	log.Printf("received %d bytes", len(httpBody))
}