mirror of
https://github.com/dragonheim/gagent.git
synced 2025-04-27 07:28:58 -07:00
fix: Re-initializing after I destroyed the original repository.
This commit is contained in:
parent
5863999e8c
commit
8b54fc32c5
20 changed files with 1359 additions and 0 deletions
43
src/client/client.go
Normal file
43
src/client/client.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
gs "git.dragonheim.net/dragonheim/gagent/src/gstructs"
|
||||
|
||||
zmq "github.com/pebbe/zmq4"
|
||||
)
|
||||
|
||||
// Main is the initiation function for a Client
|
||||
func Main(config gs.GagentConfig, agent string) {
|
||||
var mu sync.Mutex
|
||||
|
||||
fmt.Printf("Did we make it this far?\n")
|
||||
fmt.Printf("--|%#v|--\n", agent)
|
||||
|
||||
connectString := fmt.Sprintf("tcp://%s", config.Routers[0].RouterAddr)
|
||||
|
||||
sock, _ := zmq.NewSocket(zmq.DEALER)
|
||||
defer sock.Close()
|
||||
|
||||
sock.SetIdentity(config.UUID)
|
||||
sock.Connect(connectString)
|
||||
|
||||
go func() {
|
||||
mu.Lock()
|
||||
sock.SendMessage(agent)
|
||||
mu.Unlock()
|
||||
}()
|
||||
|
||||
for {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
mu.Lock()
|
||||
msg, err := sock.RecvMessage(zmq.DONTWAIT)
|
||||
if err == nil {
|
||||
fmt.Println(msg[0], config.UUID)
|
||||
}
|
||||
mu.Unlock()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue