Skip to content
Snippets Groups Projects
Commit 72ff2b70 authored by Xavier Perret's avatar Xavier Perret
Browse files

finally found a way to specify the local ip

parent 9bcd3e85
No related branches found
No related tags found
1 merge request!2added file to separate client function from the server
package manage_connection 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment