update code to current

This commit is contained in:
Merith-TK 2024-03-16 18:53:16 -07:00
parent 0a563d8b02
commit 0ad7b3f110
6 changed files with 55 additions and 17 deletions

View file

@ -1,6 +1,7 @@
package main
import (
"bufio"
"fmt"
"io/ioutil"
"log"
@ -13,6 +14,7 @@ import (
)
func main() {
log.Println("Starting client...")
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
@ -59,19 +61,42 @@ func main() {
// create execConn off of / endpoint
// BLAME COPILOT FOR THIS
// Send the contents over the lang websocket
sendSourceData := func() {
err = execConn.WriteMessage(websocket.TextMessage, sourceData)
if err != nil {
log.Fatal("Failed to send source data over lang websocket:", err)
}
}
sendSourceData()
// Listen for space key press in console
go func() {
reader := bufio.NewReader(os.Stdin)
for {
char, _, err := reader.ReadRune()
if err != nil {
log.Fatal("Failed to read from console:", err)
}
if char == ' ' {
sendSourceData()
}
}
}()
// Send the contents over the lang websocket
err = execConn.WriteMessage(websocket.TextMessage, sourceData)
if err != nil {
log.Fatal("Failed to send source data over lang websocket:", err)
}
select {
case <-interrupt:
fmt.Println("Interrupt signal received, closing connections...")
close(done)
time.Sleep(1 * time.Second)
return
}
<-interrupt
fmt.Println("Interrupt signal received, closing connections...")
close(done)
time.Sleep(1 * time.Second)
}
func connectWebSocket(urlStr string) (*websocket.Conn, error) {