@
vfx666 可以部署个服务测试一下
server.go
```
package main
import (
"fmt"
"net"
)
func handleConnection(conn net.Conn) {
defer conn.Close()
data := make([]byte, 1024*100)
// 不断向连接写入数据
for {
for i := 0; i < len(data); i += 2 {
data[i] += 177
}
_, err := conn.Write(data)
if err != nil {
fmt.Println("Error writing to connection:", err)
return
}
}
}
func main() {
listener, err := net.Listen("tcp", ":9090")
if err != nil {
fmt.Println("Error starting server:", err)
return
}
defer listener.Close()
fmt.Println("Server started. Listening on port 9090...")
for {
conn, err := listener.Accept()
if err != nil {
fmt.Println("Error accepting connection:", err)
continue
}
go handleConnection(conn)
}
}
```
local.go
```
package main
import (
"fmt"
"net"
"time"
)
// 连接数
const link_count = 6
// 服务端地址
var remote = "192.168.1.17:9090"
func main() {
var totalBytes int
var bytesRead int
for i := 0; i < link_count; i++ {
go func() {
conn, err := net.Dial("tcp", remote)
if err != nil {
fmt.Println("Error connecting to server:", err)
return
}
defer conn.Close()
fmt.Println("Connected to server.")
for {
buffer := make([]byte, 1024)
n, err := conn.Read(buffer)
if err != nil {
fmt.Println("Error reading from server:", err)
return
}
bytesRead += n
}
}()
}
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
for range ticker.C {
// fmt.Printf("Received %d bytes in the last second\n", bytesRead-totalBytes)
fmt.Printf("%dmb/s %dmbps\n", (bytesRead-totalBytes)/1024/1024, (bytesRead-totalBytes)*8/1024/1024)
totalBytes = bytesRead
}
}
```
编译一下
```
SET CGO_ENABLED=0
SET GOOS=linux
SET GOARCH=amd64
go build s.go
```