Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Revert "Merge simple-server into master"
  • Loading branch information
wrr14001 committed Jan 28, 2019
1 parent a63a043 commit 7f9ebf0
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 178 deletions.
2 changes: 0 additions & 2 deletions .gitignore

This file was deleted.

Binary file modified README.md

example-servergenerator-server

Intro

Included in this repository is the file /sender/sender.go which will attempt to make a websocket connection and run multiple senders that will each send packets to the websocket. These packets consist of an ID, a number 0, 1, or 2 which is a number of seconds to wait, and a timestamp. Your job is to build a server that will receive the packets via webosocket, wait the requested amount of time, and then send a response (one response per packet). You should read through sender.go and try to understand what is going on -- I will be around for questions no matter how trivial.

##Shared data types The data types for sending and receiving data are in /data-types/data-types.go. The sender uses the DataStruct to send data and its listeners accept ResponseStructs, so your server should also use these data types to process and send its messages.

##Build configurations You will need to create two different build configurations -- one for the sender and one for your server. Each should have the run type set to file, and then just give it the path to the .go file you want to build. Make the output and working directory the same directory with the file you're building, i.e. add /sender for the sender (and put your server in its own directory. When I did this I named it responder).

##Getting started Just to reiterate what I said in slack:

I needed to use mutexes and waitgroups for this. These are in the "sync" package. Often times I will use the words lock and mutex interchangeably because mutexes are locks that can only be opened by one lock request a time. I also had to use gorilla/websockets, which hopefully you should all have properly installed from our meeting Wednesday 12/5. Setting up the websocket requires use of the "net/http" package which is part of the core library (so you don't have to install it). I also used the "time" package, and of course I imported the data-types.go file so I could use those for my server. Here's my complete import statement in my solution:

import (
    "fmt"
    "generator-server/data-types"
    "github.com/gorilla/websocket"
    "net/http"
    "sync"
    "time"
)

Some thoughts to direct your initial planning --

  • structs are a great way to keep things together. If you're gonna have a loop that writes to a websocket and you need to manage a lock for that websocket, it might be a good idea to keep a websocket and a lock for it in a struct

  • this pattern is great for handling messages from multiple channels

    for {
        select {
        case data, ok := <-c:   // c and d are channels
            # do something
        case data, ok := <-d:
            # do something
        }
    }
    
  • Make sure you lock before writing to a websocket so that you don't get a concurrent write error

  • If your server quits too early it might be because of waitgroups -- Make sure you actually wait for waitgroups and add goroutines you want to wait for to them.

  • Ask any questions you need to, my slack pm is always open and I'll try to help you out as soon as I can.

Binary file not shown.
15 changes: 0 additions & 15 deletions data-types/data-types.go

This file was deleted.

9 changes: 9 additions & 0 deletions hello.go
@@ -0,0 +1,9 @@
package main

import (
"fmt"
)

func main() {
fmt.Printf("hello, world\n")
}
161 changes: 0 additions & 161 deletions sender/sender.go

This file was deleted.

0 comments on commit 7f9ebf0

Please sign in to comment.