DEV Community

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

Posted on • Originally published at

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 (

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 {
    daytime := time.Now().String()
    // writes data to the connection
Enter fullscreen mode Exit fullscreen mode

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

telnet 13
Enter fullscreen mode Exit fullscreen mode

Image description

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

Top comments (0)