add socket server

This commit is contained in:
w1ndyb0y
2020-12-21 17:59:15 +08:00
parent f67d00d6b8
commit 6210287123
+4 -2
View File
@@ -66,7 +66,7 @@ func start(cmd *cobra.Command, args []string) {
// `signal.Notify` registers the given channel to
// receive notifications of the specified signals.
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
run = true
utils.ServerRunning = true
// This goroutine executes a blocking receive for
// signals. When it gets one it'll print it out
@@ -83,7 +83,9 @@ func start(cmd *cobra.Command, args []string) {
// expected signal (as indicated by the goroutine
// above sending a value on `done`) and then exit.
fmt.Println("awaiting signal")
for run {
_ = utils.InitDb(dbFile, dbInit)
utils.Listen(socketAddress)
for utils.ServerRunning {
if !utils.IsPortOpen() {
log.Println("try to open port")
err := utils.OpenPort(device, baudrate, bytesize)