fixing some net connection issues

This commit is contained in:
2020-05-31 20:19:43 -04:00
parent 0051b92c47
commit 4fee4cec7d
2 changed files with 13 additions and 4 deletions

View File

@@ -8,8 +8,7 @@ import (
)
func GetServerInfo(conn *net.Conn) error {
for {
fmt.Println("New LOop")
for { // Server should send 'Connected\n' to client after connect, then client can ask for server details
message, err := bufio.NewReader(*conn).ReadString('\n')
if err != nil {
return fmt.Errorf("error reading from connection: %s", err)
@@ -18,7 +17,14 @@ func GetServerInfo(conn *net.Conn) error {
switch message {
case "Connected\n":
fmt.Println("Server has acknowledged connection, asking for server details")
conn.Send(fmt.Fprintf(*conn, "Details\n"))
bytesSent, err := fmt.Fprintf(*conn, "Details\n")
if err != nil {
fmt.Println("Error sending message to server! ", err)
os.Exit(0)
}
if bytesSent > 0 {
fmt.Println("Message Sent")
}
default:
fmt.Println("Details: ", message)
os.Exit(0)