mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-15 12:23:41 +00:00
fix examples/net/socket to work with netip API
This commit is contained in:
@@ -13,8 +13,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"machine"
|
"machine"
|
||||||
"net"
|
"net/netip"
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers/netdev"
|
"tinygo.org/x/drivers/netdev"
|
||||||
@@ -54,15 +53,13 @@ func main() {
|
|||||||
|
|
||||||
func sendBatch() {
|
func sendBatch() {
|
||||||
|
|
||||||
host, sport, _ := net.SplitHostPort(addr)
|
addrPort, _ := netip.ParseAddrPort(addr)
|
||||||
ip := net.ParseIP(host).To4()
|
|
||||||
port, _ := strconv.Atoi(sport)
|
|
||||||
|
|
||||||
// make TCP connection
|
// make TCP connection
|
||||||
message("---------------\r\nDialing TCP connection")
|
message("---------------\r\nDialing TCP connection")
|
||||||
fd, _ := dev.Socket(netdev.AF_INET, netdev.SOCK_STREAM, netdev.IPPROTO_TCP)
|
fd, _ := dev.Socket(netdev.AF_INET, netdev.SOCK_STREAM, netdev.IPPROTO_TCP)
|
||||||
err := dev.Connect(fd, "", ip, port)
|
err := dev.Connect(fd, "", addrPort)
|
||||||
for ; err != nil; err = dev.Connect(fd, "", ip, port) {
|
for ; err != nil; err = dev.Connect(fd, "", addrPort) {
|
||||||
message(err.Error())
|
message(err.Error())
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user