Rush: Frozen

https://systembash.com/a-simple-go-tcp-server-and-tcp-client/

Internet Relay Chat (IRC): facilitates communication in the form of text; designed for group communication, discussion forums, private messages, etc.

Go’s built-in functions:
- Goroutines
- Channels

IRC server: concurrent program, in which computations are performed in an interleaved fashion.

Tour of Go: https://tour.golang.org/welcome/1

**THIS IS A LENGTHY/LONG MODULO…Honestly, if you have the time, sure, do it. Otherwise, just google what you need to do. It is useful though to gain an understanding of go langauge**
Programs are made up packages with the package main running.

fmt = format

The statements in the imports are in a “factored” import statement.

A name is exported if it begins with a capital letter. When importing a package, you must refer to its exported name (eg. math.Pi not math.pi).

Go functions can take in zero or more arguments, but the type comes after the variable name because of its left to right read functionality. Normally variables are declared as x:int and p: pointer to int. This was simplified to x int and p *int.

In terms of readability when creating functions, it’s easier since its read from left to right.

func main(int, []string) int

The main is a function that takes in int and and an array of strings and returns and int. The function name comes first, making it easier to read.

(https://blog.golang.org/gos-declaration-syntax).

In C, writing the type in the parenthesis, especially in terms of multiple function pointers, can be confusing:
int (*(*fp)(int (*)(int, int), int))(int, int)

When 2 or more named function parameters share a type, omit the type from all but the last:
x int, y int → x, y int

The := shows declaring and assignment of the variable in Go language. It infers the variable’s data type automatically.

In Go, := is for declaration + assignment, whereas = is for assignment only. For example, var foo int = 10 is the same as foo := 10

Returning multiple results (string, string).

In short functions, named return values can be written in the function declaration portion. The return statement without arguments returned the named return values (“naked return”). This is used in short functions and can harm readability in longer functions.

Declaring variables:
var c, python, java bool

Variables with initializers:
You can omit the type because Go will infer the language
var c, python, java = true, false, “no!”

Short variable declaration:
Can only be done within a function
k := 3

Basic Types in Go:
bool
string
int int8 int16 int32 int64
uint uint8 uint16 uint32 uint64 uintptr
byte // alias for uint8
rune // alias for int32
// represents a Unicode code point
float32 float64
complex64 complex128

You can use %T to find the type.

Variable declaration without an explicit initial value are given their zero value:
Numerical type: 0
Boolean type: false
Strings: “”

Conversion of Type
T(v) converts the value v to the type T

Constants
Can be character, str, bool, or numeric values. Cannot be declared using :=
const World = “Hello”

Numeric Constants
high-precision values

Concurrency in Go Programming
https://www.golang-book.com/books/intro/10
Not the same as parallelism. Parallelism is running two things at exactly the same time. In concurrency, it is about breaking up a program into independent tasks that can run at the same time.

Foor example, go an run the first function in the background adn then continue to the next function immediately.

go count(“sheep”) //This is a go routine
count(“fish”)

They run side by side (“go routine”). When the main go routine finishes, then it exits automatically. That is why scanln is needed.

nc = gateway to make 2 pc connect with each other
nc localhost 6667

Channel in Go Programming
https://www.geeksforgeeks.org/channel-in-golang/
Channel: a way for two goroutine to communicate with each other. Data can be sent and received by two different goroutines.

Vocabulary Terms
Sandbox: tester server/working directory. Enables isolated execution of a program

Installing Go on the MAC Computer (Thanks to elee, mlin, pfu)
step 1:
type !brew to Kane on Slackstep 2:
copy the first block and paste it in terminal
wait for a few minutes to downloadstep 3:
vim .zshrc
add those 2 lines (from the second block in Kane) at the end of filestep 4:
type in terminal:
brew install go
wait for a few minutes to installstep 5:
vim .zshrc in home directory
copy and paste the following 2 lines to end of file:
GOPATH="${HOME}/.go"
GOROOT="$(brew --prefix golang)/libexec"Now go is installed on your account.

Make a test file hello.go to check if it works:
e.g.:
hello.go:
package mainimport "fmt"func main() {
fmt.Println("Hello, 世界")
}

To compile a .go file, type:
go build hello.goTo run it, type:
./helloFor a shortcut, to compile and run at the same time, type:
go run

To Create a Server:
server, err := net.Listen(“tcp”, port)
tcp = transmission control protocol. It basically acts as a quality checker to make sure the information passes appropriately
There is udp and tcp.
Protocol: a standard of communication (eg. English, Spanish, French)
TCP: Sent package and acknowledges what is sent to them
→ “Message read”
UDP: Only send the package. Don’t care if it is received.
→ Amazon delivering packages

Tim’s Cheatsheet to Sending a Message to Another PC
ifconfig → Get the IP address
nc ip_address port

Control + Z = suspend → meaning it’s semi running. You can go back to it. If you suspend it on the server, it will still be running in the background. You need to use % in the terminal to get back tot he last server and then kill it via Control + C.

AKA: Use Control + C (close)

— — — — — — — — — — — — — -
Additional Links/References:
https://www.youtube.com/watch?v=C8LgvuEBraI
https://github.com/jjaniec/Frozen

— — — — — — — — — — — — — —
Previously Learned:

write(0, ‘c’, 1);
write(1, ‘c’, 1);
write(2, ‘c’, 1);

--

--