Community

CHAT-gpt에게 golang 소켓 코드 요청한 후 결과

package main import (  "fmt"  "net"  "os" ) const (  connHost = "localhost"  connPort = "8000"  connType = "tcp" ) func main() {  // Connect to the server  conn, err := net.Dial(connType, connHost+":"+connPort)  if err != nil {   fmt.Println("Error connecting:", err.Error())   os.Exit(1)  }  // Send some data  _, err = conn.Write([]byte("Hello Server!"))  if err != nil {   fmt.Println("Error writing:", err.Error())   os.Exit(1)  }  // Receive some data  buffer := make([]byte, 1024)  n, err := conn.Read(buffer)  if err != nil {   fmt.Println("Error reading:", err.Error())   os.Exit(1)  }  // Print the received data  fmt.Println("Received:", string(buffer[:n]))  // Close the connection  conn.Close() }

알림

알림이 없습니다