Skip to content

KairosSystems/GoServerDetect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoServerDetect

Detect Server via UDP Broadcasting

Information

You can share arbitrary data in []byte{} to the client, the preshared key must be the same in the server and client to send data from the server to the client

Example

Server

package main

import (
	"encoding/json"
	"github.com/KairosSystems/GoServerDetect"
	"log"
)

type DiscoveredData struct {
	Name string `json:Name`
}

func main() {
	response := &DiscoveredData{Name: "Arbitrary Data"}
	data, err := json.Marshal(response)
	if err != nil {
		log.Fatal(err)
	}
	_ = GoServerDetect.CreateServer(8888, "PresharedKey", data)
}

Client

package main

import (
	"encoding/base64"
	"encoding/json"
	"github.com/KairosSystems/GoServerDetect"
	"github.com/KairosSystems/GoServerDetect/Models"
	"log"
)

type DiscoveredData struct {
	Name string `json:Name`
}

func main() {
	data, _ := GoServerDetect.DiscoverServer(8888, "PresharedKey")
	response := &Models.ServerResponse{}
	_ = json.Unmarshal(data, &response)
	decoded, _ := base64.StdEncoding.DecodeString(response.Data)
	payload := &DiscoveredData{}
	_ = json.Unmarshal(decoded, &payload)
	log.Println(string(data))
}

Releases

No releases published

Packages

No packages published

Languages