From 72ff2b7034e187eef7ab5d49d77796a10f55071d Mon Sep 17 00:00:00 2001 From: Xavier Perret <xa.perret@outlook.com> Date: Sat, 29 Oct 2022 13:11:46 +0200 Subject: [PATCH] finally found a way to specify the local ip --- app/manage-connection/manage-connection.go | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/manage-connection/manage-connection.go b/app/manage-connection/manage-connection.go index d461671..0022c4c 100644 --- a/app/manage-connection/manage-connection.go +++ b/app/manage-connection/manage-connection.go @@ -1 +1,30 @@ package manage_connection + +import ( + "fmt" + "net" +) + +func CreateConnection(destinationAddress string) net.Conn { + fmt.Println("Trying to connect to ", destinationAddress) + // connect to ip with tcp and add the ip of the sender to the connection + conn, err := net.Dial("tcp", destinationAddress) + + if err != nil { + fmt.Println("Error while connecting to the neighbour", err) + } + + return conn +} + +func CreateConnectionWithSpecifiedLocalAddress(senderAddress string, destinationAddress string) net.Conn { + dialer := net.Dialer{LocalAddr: &net.TCPAddr{IP: net.ParseIP(senderAddress)}} + + conn, err := dialer.Dial("tcp", destinationAddress) + + if err != nil { + fmt.Println("Error while connecting to the neighbour", err) + } + + return conn +} \ No newline at end of file -- GitLab