Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Revert "Merge simple-server into master" #3
Revert "Merge simple-server into master" #3
Changes from all commits
7f9ebf0
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
This file was deleted.
example-servergenerator-serverIntro
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 theDataStruct
to send data and its listeners acceptResponseStructs
, 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 thedata-types.go
file so I could use those for my server. Here's my complete import statement in my solution: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
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.
This file was deleted.
This file was deleted.