Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "io"
- "net"
- )
- func main() {
- listener, serverStartError := net.Listen("tcp", "127.0.0.1:1234")
- if serverStartError != nil {
- fmt.Println("Error starting the server: " + serverStartError.Error())
- }
- defer listener.Close()
- for {
- conn, listenerAcceptError := listener.Accept()
- if listenerAcceptError != nil {
- fmt.Println("Error accepting listener connection: " +
- listenerAcceptError.Error())
- }
- fmt.Println("New connection: " + conn.RemoteAddr().String())
- go handleConnection(conn)
- }
- fmt.Scanln()
- }
- func handleConnection(conn net.Conn) {
- tmp := make([]byte, 1024)
- buf := make([]byte, 0, 2)
- for {
- n, err := conn.Read(tmp)
- fmt.Println(n)
- if err != nil {
- fmt.Println("ERROR", err.Error())
- if err != io.EOF {
- fmt.Println("EOF ERROR")
- }
- break
- }
- fmt.Println("APPENDING")
- buf = append(buf, tmp[:n]...)
- }
- fmt.Println(buf)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement