Skip to content

Commit

Permalink
fix examples/net/socket to work with netip API
Browse files Browse the repository at this point in the history
  • Loading branch information
scottfeldman authored and deadprogram committed Dec 6, 2023
1 parent 8f4b90c commit f06d288
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions examples/net/socket/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import (
"fmt"
"log"
"machine"
"net"
"strconv"
"net/netip"
"time"

"tinygo.org/x/drivers/netdev"
Expand Down Expand Up @@ -54,15 +53,13 @@ func main() {

func sendBatch() {

host, sport, _ := net.SplitHostPort(addr)
ip := net.ParseIP(host).To4()
port, _ := strconv.Atoi(sport)
addrPort, _ := netip.ParseAddrPort(addr)

// make TCP connection
message("---------------\r\nDialing TCP connection")
fd, _ := dev.Socket(netdev.AF_INET, netdev.SOCK_STREAM, netdev.IPPROTO_TCP)
err := dev.Connect(fd, "", ip, port)
for ; err != nil; err = dev.Connect(fd, "", ip, port) {
err := dev.Connect(fd, "", addrPort)
for ; err != nil; err = dev.Connect(fd, "", addrPort) {
message(err.Error())
time.Sleep(5 * time.Second)
}
Expand Down

0 comments on commit f06d288

Please sign in to comment.