Things used in this project

Code

server.goGo
sample of server code
package main

import (
	"bytes"
	"fmt"
	"gitlab.com/bobburns/famsess"
	"log"
	"net"
	"os"
)

func main() {
	service := ":16538"
	tcpAddr, err := net.ResolveTCPAddr("tcp4", service)
	checkError(err)

	listener, err := net.ListenTCP("tcp", tcpAddr)
	checkError(err)

	for {
		conn, err := listener.Accept()
		if err != nil {
			continue
		}
		defer conn.Close()
		fmt.Println("listening on port ", service)
		go handleClient(conn)
	}
}
func handleClient(conn net.Conn) {
	s := session.NewSession(conn)

	for {
		log.Println("main loop")
		err := s.ParseIncoming()
		if err != nil {
			log.Printf("Error ParseIncoming [%s]\n", err)
			break
		}

		switch {
		  
		case bytes.Equal(s.RecOp[0:4], session.SendMPre[0:4]):
			log.Println("got SENDMPRE")
			err = s.MessagePreRecv()
		case bytes.Equal(s.RecOp[0:4], session.SendMess[0:4]):
			err = s.MessageRecv()
		case bytes.Equal(s.RecOp[0:4], session.RetrMess[0:4]):
			err = s.MessageRetr()
		case bytes.Equal(s.RecOp[0:4], session.ClientAuth[0:4]):
			err = s.ServerAuth()
		case bytes.Equal(s.RecOp[0:4], session.MessInit[0:4]):
			err = s.MessageInit()
		case bytes.Equal(s.RecOp[0:4], session.ReqMeta[0:4]):
			err = s.ServMeta()
		case bytes.Equal(s.RecOp[0:4], session.DelMess[0:4]):
			err = s.MessageServDel()
		case bytes.Equal(s.RecOp[0:4], session.CChPass[0:4]):
			err = s.ServerChgPass()

		}
		if err != nil {
			// how to handle errors?
			log.Println(err)
		}
		fmt.Println(s.RecOp[0:4])
	}
}

func checkError(err error) {
	if err != nil {
		fmt.Printf("Error: %s\n", err)
		os.Exit(1)
	}
}

Credits

8biticon jec6fced6s
Bob Burns

Started programming again after 25? years. Currently super into Golang and what it can do with pocketCHIP.

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Face Detection Using OpenCV With Raspberry Pi
Intermediate
  • 3,426
  • 32

Protip

In this project, we are going to detect faces using OpenCV with Raspberry Pi.

Third Eye for The Blind
Intermediate
  • 1,131
  • 14

Full instructions

An innovative wearable technology for visually impaired peoples.

Creating an IoT Server with Home Assistant and MQTT
Intermediate
  • 3,783
  • 21

Protip

This guide will help you set up Home Assistant. Access it from any web browser and automations.

Automated GPS Controlled Photo Taker
Intermediate
  • 1,786
  • 20

For this build, I put together a backpack to take pictures when I am close to places that I like; especially in London.

DIY Smart Assistant Speaker/Lamp (Google Home or Alexa)
Intermediate
  • 2,016
  • 5

Full instructions

DIY build using 3D printed enclosure and parts, a recycled Bluetooth speaker, a Raspberry Pi, and a Philips Hue light bulb.

Cat Door with Pet Recognition
Intermediate
  • 4,694
  • 22

Full instructions

Use object detection to let your cat in and out of the house with a motion-activated pet door.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login