Last active
August 2, 2018 18:40
-
-
Save JVero/3bb7a894ba7c7b9832ea11e4711d1ed2 to your computer and use it in GitHub Desktop.
very basic UDP server and client with test. net.Dial creates different addresses even though I set the port to 9000
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package client | |
import ( | |
"fmt" | |
"testing" | |
a "../go_server" | |
) | |
func TestPort(t *testing.T) { | |
server := a.CreateServer("9000") | |
client := CreateClient("9000") | |
fmt.Println(client.LocalAddr()) | |
fmt.Println(server.LocalAddr()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package client | |
import ( | |
"log" | |
"net" | |
) | |
func CreateClient(port string) net.Conn { | |
client, err := net.Dial("udp", "localhost:"+port) | |
if err != nil { | |
log.Fatal(err) | |
} | |
return client | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package server | |
import ( | |
"net" | |
) | |
func CreateServer(port string) net.Conn { | |
conn, _ := net.Dial("udp", "localhost:"+port) | |
defer conn.Close() | |
return conn | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment