Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/antosmichael07/go-tcp-connection
A library meant to simplify the process of making TCP request and responses.
https://github.com/antosmichael07/go-tcp-connection
client connection go golang server tcp tcp-client tcp-server tcp-socket
Last synced: 7 days ago
JSON representation
A library meant to simplify the process of making TCP request and responses.
- Host: GitHub
- URL: https://github.com/antosmichael07/go-tcp-connection
- Owner: antosmichael07
- Created: 2024-06-04T17:48:25.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-08-01T06:25:33.000Z (4 months ago)
- Last Synced: 2024-08-01T08:01:52.999Z (4 months ago)
- Topics: client, connection, go, golang, server, tcp, tcp-client, tcp-server, tcp-socket
- Language: Go
- Homepage:
- Size: 67.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Go-TCP-Connection
A library meant to simplify the process of making TCP request and responses.
Install with `go get github.com/antosmichael07/Go-TCP-Connection`## Example
### Server
```go
package mainimport (
"fmt"lgr "github.com/antosmichael07/Go-Logger"
tcp "github.com/antosmichael07/Go-TCP-Connection"
)const (
event_test uint16 = iota + 4
)func main() {
server := tcp.NewServer("localhost:8080")
server.Logger.Level = lgr.Warningserver.OnConnect(func(conn *tcp.Connection) {
msg := []byte("Hello from the server")
server.SendData(conn, event_test, &msg)
})server.On(event_test, func(data *[]byte, conn *tcp.Connection) {
fmt.Println("Received data from client:", string(*data))
})server.Start()
}
```### Client
```go
package mainimport (
"fmt"lgr "github.com/antosmichael07/Go-Logger"
tcp "github.com/antosmichael07/Go-TCP-Connection"
)const (
event_test uint16 = iota + 4
)func main() {
client := tcp.NewClient("localhost:8080")
client.Logger.Level = lgr.Warning
client.Connect()client.On(event_test, func(data *[]byte) {
fmt.Println("Received data from the server: ", string(*data))msg := []byte("Hello from the client")
client.SendData(event_test, &msg)
})client.Listen()
}
```