Skip to content

Commit

Permalink
reformatting of reader
Browse files Browse the repository at this point in the history
  • Loading branch information
STollenaar committed Sep 30, 2022
1 parent 8b78dc7 commit ac67161
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "main.go",
"env": {
"PORT": "4269"
}
}
]
}
23 changes: 20 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package main

import (
"errors"
"fmt"
"io"
"net"
"os"
)

var EOF = errors.New("EOF")

func main() {
ln, err := net.Listen("tcp", ":"+os.Getenv("PORT"))
if err != nil {
Expand All @@ -28,7 +30,22 @@ func main() {
func handle(conn net.Conn) {
defer conn.Close()

if _, err := io.Copy(conn, conn); err != nil {
fmt.Println("copy: ", err.Error())
buff := make([]byte, 32*1024)
for {
messageLength, err := conn.Read(buff)

if err != nil {
if err != EOF {
fmt.Println("Error reading data: ", err)
}
break
}

_, err = conn.Write(buff[0:messageLength])

if err != nil {
fmt.Println("Error writing data: ", err)
break
}
}
}

0 comments on commit ac67161

Please sign in to comment.