Junior — Middle
What tools do you use for diagnosing and testing TCP connections?
sobes.tech AI
Answer from AI
For diagnosing and testing TCP connections in Go, the following tools and methods are often used:
- net.Dial and net.Listen — standard functions for establishing and listening to TCP connections, allowing to check basic functionality.
- tcpdump or Wireshark — external tools for analyzing network traffic, helping to see packets and understand what happens at the protocol level.
- telnet or nc (netcat) — for simple testing of TCP ports and connections.
- Go profilers and logging — for debugging and monitoring the operation of TCP servers and clients.
Example of a simple TCP client in Go:
package main
import (
"fmt"
"net"
"time"
)
func main() {
conn, err := net.DialTimeout("tcp", "example.com:80", 5*time.Second)
if err != nil {
fmt.Println("Connection error:", err)
return
}
defer conn.Close()
fmt.Println("Connection established")
}