diff options
| author | onur1 <onur1@onurgunduz.com> | 2024-11-09 06:31:28 +0100 |
|---|---|---|
| committer | onur1 <onur1@onurgunduz.com> | 2024-11-09 06:31:28 +0100 |
| commit | e8d51fed2fa8c480d2cd9149309291dba1e1bc12 (patch) | |
| tree | 853ba2b82121bf6e49ec3678fbb0b7b91dd88008 | |
| parent | c4ad4cedb47c700a0676479624514159be4894ed (diff) | |
| download | muxer-e8d51fed2fa8c480d2cd9149309291dba1e1bc12.tar.gz muxer-e8d51fed2fa8c480d2cd9149309291dba1e1bc12.zip | |
Update README
| -rw-r--r-- | README.md | 95 |
1 files changed, 94 insertions, 1 deletions
@@ -1,3 +1,96 @@ + # binproto -binproto implements low-level support for binary-based two-way communication protocols. You can use it to create your own low-latency binary protocols for things like game networking or file transfer. +`binproto` is a lightweight Go library designed to facilitate low-level binary protocol communication. It enables efficient, multiplexed messaging, making it well-suited for network applications requiring reliable and fast binary data exchange. + +## Features + +- **Multiplexed Channels**: Supports multiple channels over a single connection. +- **Efficient Framing**: Provides an efficient and easy-to-use binary framing mechanism. +- **Customizable Buffers**: Allows control over buffer sizes for optimized performance. + +## Installation + +Install `binproto` by running: + +```sh +go get github.com/onur1/binproto +``` + +## Usage + +Here’s a basic example of how to use `binproto` for a simple client-server communication setup: + +```go +package main + +import ( + "log" + "net" + "github.com/onur1/binproto" +) + +func main() { + // Create a new server instance + server := &Server{} + + // Start the server + go func() { + if err := server.Start(":4242"); err != nil { + log.Fatal(err) + } + }() + + // Connect a client + client, err := binproto.Dial("tcp", ":4242") + if err != nil { + log.Fatal(err) + } + + // Send a message from the client + client.Send(binproto.NewMessage(1, 1, []byte("Hello Server"))) + + // Close the client + client.Close() +} +``` + +### Server Code + +To set up a server using `binproto`, create a handler to process incoming messages. + +```go +type Server struct { + listener net.Listener +} + +func (s *Server) Start(addr string) error { + l, err := net.Listen("tcp", addr) + if err != nil { + return err + } + s.listener = l + for { + conn, err := s.listener.Accept() + if err != nil { + return err + } + go s.handleConnection(conn) + } +} + +func (s *Server) handleConnection(conn net.Conn) { + c := binproto.NewConn(conn) + for { + msg, err := c.ReadMessage() + if err != nil { + return + } + log.Printf("Received message: %s", msg.Data) + } +} +``` + +## License + +MIT License. See [LICENSE](LICENSE) for details. |
