Sobes.tech
Senior

On which levels of the OSI model have you worked?

sobes.tech AI

Answer from AI

In my work with Golang, I most often interacted with the OSI model layers, starting from the transport layer and above:

  • Transport layer (4th): working with TCP and UDP connections, implementing network protocols, configuring timeouts, managing data streams.
  • Network layer (3rd): sometimes dealing with IP addressing, routing, for example, when writing network utilities or services.
  • Application layer (7th): implementing HTTP/HTTPS clients and servers, working with REST API, WebSocket, gRPC.

Example in Go for a TCP server:

package main

import (
    "fmt"
    "net"
)

func main() {
    ln, err := net.Listen("tcp", ":8080")
    if err != nil {
        panic(err)
    }
    defer ln.Close()

    for {
        conn, err := ln.Accept()
        if err != nil {
            fmt.Println("Connection error:", err)
            continue
        }
        go handleConnection(conn)
    }
}

func handleConnection(conn net.Conn) {
    defer conn.Close()
    buf := make([]byte, 1024)
    n, err := conn.Read(buf)
    if err != nil {
        fmt.Println("Read error:", err)
        return
    }
    fmt.Println("Received:", string(buf[:n]))
    conn.Write([]byte("Hello from the server!"))
}

Thus, I worked with the transport and application layers, and also had a general understanding of the network layer.