DEV Community

Cover image for Daytime Protocol RFC-867 in Golang
Deepankar Bhade
Deepankar Bhade

Posted on • Originally published at dpnkr.in

2 2

Daytime Protocol RFC-867 in Golang

Daytime service is a useful debugging and measurement tool. A daytime
service simply sends a current date and time as a character string
without regard to the input.
Based on RFC-867

We will be building a Daytime service using TCP in this short example. We will create a server listening for TCP connections on TCP port 13, after the connection is established we will send back the date response.

Sounds easy? Because it is! I have ignored handling errors in the code to make it simple.

package main

import (
  "net"
  "time"
)

func main() {
  addr := ":13"
  tcpAddr, _ := net.ResolveTCPAddr("tcp", addr)
  // listens on PORT 13
  listener, _ := net.ListenTCP("tcp", tcpAddr)
  for {
    // wait for client to connect
    // when client connects, the accept call returns connection
    conn, err := listener.Accept()
    if err != nil {
      continue
    }
    daytime := time.Now().String()
    // writes data to the connection
    conn.Write([]byte(daytime))
    conn.Close()
  }
}
Enter fullscreen mode Exit fullscreen mode

Then run this code and test it out using telnet you will see the response.

telnet 127.0.0.1 13
Enter fullscreen mode Exit fullscreen mode

Image description

Hope you’ve learned something new, thanks for reading this tiny blog!

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more