Last active
April 12, 2021 19:47
-
-
Save JJTech0130/db0b3f0a05cab1b307141ba4071b2e73 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"crypto/tls" | |
"log" | |
"strings" | |
//"io" | |
"encoding/json" | |
) | |
func handleErr(err error) { | |
if err != nil { | |
log.Println(err) | |
return | |
} | |
} | |
func connect(addr string) (*bufio.ReadWriter, error) { | |
conn, err := tls.Dial("tcp", addr, &tls.Config{InsecureSkipVerify: true}) | |
if err != nil { | |
return nil, err | |
} | |
return bufio.NewReadWriter(bufio.NewReader(conn), bufio.NewWriter(conn)), nil | |
} | |
func send(conn *bufio.ReadWriter, msg string) string { | |
_, err := conn.WriteString(msg + "\r\n") | |
handleErr(err) | |
err = conn.Flush() | |
handleErr(err) | |
response, err := conn.ReadString('\n') | |
handleErr(err) | |
t := strings.Trim(response, " \r\n") | |
return t | |
} | |
func main() { | |
conn, err := connect("192.168.0.5:8081") | |
if err != nil { | |
log.Println(err) | |
return | |
} | |
ping := map[string]interface{}{ | |
"CommuniqueType": "ReadRequest", | |
"Header": map[string]interface{}{ | |
"Url": "/server/status/ping", | |
}, | |
} | |
response := send(conn, json.Marshal(ping)) | |
println(response) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment