I am getting an IP address and port number from a Bittorrent tracker, for a specific torrent file. It represents a peer on the bittorrent network. I am trying to connect to the peer using this code. The connection always times out (getsockopt: operation timed out). I think I am missing something very fundamental here, because I tried the same code in python with the exact same result, operation timed out. It happens for every single peer IP address.
I downloaded this bittorrent client - https://github.com/jtakkala/tulva which is able to connect to peers from my system using this type of code (Line 245, peer.go). I have also been able to use similar code for connecting to a tcp server running on localhost.
Edited details after JimB's comment and Kenny Grant's answer
package main
import (
"fmt"
"net"
)
func main() {
raddr := net.TCPAddr{IP: []byte{}/*This byte slice contains the IP*/, Port: int(/*Port number here*/)}
conn, err := net.DialTCP("tcp4", nil, &raddr)
if err != nil {
fmt.Println("Error while connecting", err)
return
}
fmt.Println("Connected to ", raddr, conn)
}