2018-12-01 03:02:41 -05:00
|
|
|
package samforwardertest
|
|
|
|
|
|
|
|
import (
|
2018-12-01 03:09:03 -05:00
|
|
|
"log"
|
2018-12-01 14:40:33 -05:00
|
|
|
"net"
|
2019-06-14 01:09:55 -04:00
|
|
|
//"net/http"
|
2018-12-01 03:09:03 -05:00
|
|
|
"testing"
|
|
|
|
"time"
|
2018-12-01 03:02:41 -05:00
|
|
|
)
|
|
|
|
|
2018-12-20 20:40:24 -05:00
|
|
|
func countdown(i int) {
|
2019-01-22 17:15:04 -05:00
|
|
|
for i > 0 {
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
i--
|
2019-06-12 09:16:13 -04:00
|
|
|
if i%10 == 0 {
|
|
|
|
log.Println("Waiting", i, "more seconds.")
|
|
|
|
}
|
2019-01-22 17:15:04 -05:00
|
|
|
}
|
2018-12-20 20:40:24 -05:00
|
|
|
}
|
|
|
|
|
2019-06-14 01:09:55 -04:00
|
|
|
/*
|
2018-12-01 03:02:41 -05:00
|
|
|
func TestTCP(t *testing.T) {
|
2018-12-01 03:09:03 -05:00
|
|
|
go serve()
|
2019-06-12 09:16:13 -04:00
|
|
|
countdown(61)
|
2018-12-01 03:09:03 -05:00
|
|
|
go client()
|
2019-06-12 09:16:13 -04:00
|
|
|
countdown(61)
|
2018-12-01 03:09:03 -05:00
|
|
|
resp, err := http.Get("http://127.0.0.1:" + cport + "/test.html")
|
2019-01-22 17:15:04 -05:00
|
|
|
log.Println("requesting http://127.0.0.1:" + cport + "/test.html")
|
2018-12-01 03:09:03 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
log.Println(resp)
|
2018-12-01 03:02:41 -05:00
|
|
|
}
|
2019-06-14 01:09:55 -04:00
|
|
|
*/
|
2018-12-01 03:09:03 -05:00
|
|
|
func TestUDP(t *testing.T) {
|
2018-12-01 14:40:33 -05:00
|
|
|
go echo()
|
2019-06-12 09:16:13 -04:00
|
|
|
countdown(11)
|
|
|
|
echoclient()
|
|
|
|
countdown(11)
|
2018-12-01 14:40:33 -05:00
|
|
|
go serveudp()
|
2019-06-12 09:16:13 -04:00
|
|
|
countdown(61)
|
2018-12-01 14:40:33 -05:00
|
|
|
go clientudp()
|
2019-06-12 09:16:13 -04:00
|
|
|
countdown(61)
|
2018-12-02 12:04:05 -05:00
|
|
|
setupudp()
|
|
|
|
|
|
|
|
conn, err := net.DialUDP("udp", udplocaladdr, ssulocaladdr)
|
2018-12-01 14:40:33 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-06-12 09:16:13 -04:00
|
|
|
message := []byte("Hello UDP")
|
2018-12-02 12:04:05 -05:00
|
|
|
_, err = conn.Write(message)
|
2018-12-01 20:07:52 -05:00
|
|
|
if err != nil {
|
2019-06-12 09:16:13 -04:00
|
|
|
t.Fatal("UDP error", err)
|
2018-12-01 20:07:52 -05:00
|
|
|
}
|
2018-12-02 12:04:05 -05:00
|
|
|
log.Println(string(message))
|
2018-12-01 03:02:41 -05:00
|
|
|
}
|