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

Pulse Train Hat for Raspberry Pi Mecanum Bot Example
Intermediate
  • 743
  • 15

Full instructions

With this example, we show how to use the PTHAT and wireless Xbox controller to control a Mecanum Bot.

GooglePi - Google Assistant on Raspberry Pi
Intermediate
  • 15,334
  • 85

Full instructions

A DIY Google Home using your Raspberry Pi.

Smart Garden
Intermediate
  • 600
  • 5

Smart Garden is plant environmental monitoring system.

Pre-Collision Assist with Pedestrian Detection - Honda Civic
Intermediate
  • 1,652
  • 19

Full instructions

Combine Walabot's RF radar with real-time hazard detection and classification from camera, powered by TensorFlow with YOLO approach.

Detect Motion With OpenCV, No PIR Sensor Needed
Intermediate
  • 819
  • 14

Full instructions

If you have a HAT connected to your Raspberry Pi, you can't use your GPIO. But what if you want to detect motion? This project can help!

Pigeon: A 3D-Printed, Pi Zero W-Powered Cloud Camera
Intermediate
  • 1,266
  • 26

Full instructions

Pigeon is a simple cloud home surveillance camera project that uses the new Raspberry Pi Zero W single-board computer ($10).

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Feedback