ok, maybe this is useful to you.
This code opens a TCP Line plugged into the port `8080` using golang.
package main
import (
"fmt"
"net"
"log"
)
func main() {
l, e := net.Listen("tcp", ":8080")
if e != nil {
log.Fatal(e)
}
for {
c, e := l.Accept()
if e != nil {
log.Println(e)
continue
}
b := make([]byte, 1024)
_, e = c.Read(b)
if e != nil {
log.Println(e)
continue
}
fmt.Println(string(b[:]))
}
}
and this code sends an empty payload from the other side of that TCP line.
try to populate the buffer `b` with some data.
package main
import (
"net"
"log"
)
func main() {
c, e := net.Dial("tcp", ":8080")
if e != nil {
log.Fatal(e)
}
b := make([]byte, 1024)
_, e = c.Write(b)
if e != nil {
log.Println(e)
}
}
Both code must exist in different projects `go mod init programa` and in another folder `go mod init programb` and you paste one code in one folder and the other code in the other folder.
Read the code. READ THE DOCUMENTATION of `net.Listen`, `net.Dial` and other standard library constructs.
Understand through documentation what the function needs and what the function returns back.
Understand the documentation and assembly code using it.
https://pkg.go.dev/net@go1.26.3#Listener
https://pkg.go.dev/net@go1.26.3#Conn
https://pkg.go.dev/net@go1.26.3#Dial
>why?
Is good to learn how to write proof of concepts.