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

Raspberry Pi Motion Tracking Gun Turret
Intermediate
  • 7
  • 2

Full instructions

A motion tracking airsoft or nerf gun turret with autonomous and manual operation modes, controlled by a Raspberry Pi.

Sigfox Forest Fire Detector
Intermediate
  • 2,491
  • 16

Full instructions

How to prevent forest from burning? A small Sigfox signal can prevent natural disasters. We will use an Arduino MKRFOX + a flame detector.

Audio DAC Hat for Pi with Headphone Jack and 3W Speaker Out
Intermediate
  • 22
  • 1

Full instructions

Make your own DAC hat for Raspberry Pi 3, Raspberry Pi Zero, Raspberry Pi Zero W that has a Headphone jack and 3W Stereo speaker out.

LoRaWAN for Raspberry Pi with Worldwide Frequency Support
Intermediate
  • 3,985
  • 18

Full instructions

LoRaWAN LMIC 1.6 for Raspberry Pi with Dragino LoRA/GPS HAT or standalone RFM95W LoRa Module.

Human-Following Robot with Kinect
Intermediate
  • 2,667
  • 24

Full instructions

Instead of using single camera and complicated image recognition algorithms we can take advantage of Kinect libraries.

Automated Indoor Gardener
Intermediate
  • 4,043
  • 40

Full instructions

Never worry about dead plants again. This automated gardener never forgets to water your plants and provide artificial sunlight.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog