Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/axiaoxin/netpro
golang network programming
https://github.com/axiaoxin/netpro
Last synced: 12 days ago
JSON representation
golang network programming
- Host: GitHub
- URL: https://github.com/axiaoxin/netpro
- Owner: axiaoxin
- Created: 2019-09-12T13:03:30.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-08T10:46:56.000Z (about 5 years ago)
- Last Synced: 2024-11-07T13:55:23.259Z (2 months ago)
- Language: Go
- Homepage:
- Size: 55.7 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
netpro
======Golang net programming
## Example
Running a tcp server [tcpserver.go](https://raw.githubusercontent.com/axiaoxin/netpro/master/example/tcpserver.go)
```
package main
import (
"context"
"log""github.com/axiaoxin/netpro"
)func handler(ctx context.Context) error {
conn := netpro.CtxTCPConn(ctx)for {
buf := make([]byte, 1024)
n, err := conn.Read(buf)
if err != nil {
log.Println(err)
return err
}
log.Printf("rev %d bytes, data:%s\n", n, string(buf[:n]))
}
}func main() {
server := netpro.NewTCPServer(":9090", true)
server.Run(handler)
}
```Running an udp server [udpserver.go](https://raw.githubusercontent.com/axiaoxin/netpro/master/example/udpserver.go)
```
package mainimport (
"context"
"log""github.com/axiaoxin/netpro"
)func handler(ctx context.Context) error {
conn := netpro.CtxUDPConn(ctx)
buf := make([]byte, 128)
n, err := conn.Read(buf)
if err != nil {
log.Println(err)
return err
}
log.Println("rev data:", string(buf[:n]))
return nil
}func main() {
server := netpro.NewUDPServer(":9090")
server.Run(handler)
}
```## Config
Copy the `config.toml.example` to your workdir as `config.toml`