<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Alice Williams</title>
    <description>The latest articles on Forem by Alice Williams (@alicewilliamstech).</description>
    <link>https://forem.com/alicewilliamstech</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F431989%2Fb1ab2b6b-d65b-4f11-bfa5-a74f031cac22.png</url>
      <title>Forem: Alice Williams</title>
      <link>https://forem.com/alicewilliamstech</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/alicewilliamstech"/>
    <language>en</language>
    <item>
      <title>Getting Started with Sockets Concurrently in GoLang</title>
      <dc:creator>Alice Williams</dc:creator>
      <pubDate>Wed, 15 Jul 2020 06:35:22 +0000</pubDate>
      <link>https://forem.com/alicewilliamstech/getting-started-with-sockets-in-golang-2j66</link>
      <guid>https://forem.com/alicewilliamstech/getting-started-with-sockets-in-golang-2j66</guid>
      <description>&lt;h1&gt;
  
  
  Getting Started with Sockets Concurrently in GoLang
&lt;/h1&gt;



&lt;h3&gt;
  
  
  What are sockets?
&lt;/h3&gt;

&lt;p&gt;Sockets, or 'Web Sockets', are a TCP-based internet &lt;a href="https://tools.ietf.org/html/rfc6455#section-1.7"&gt;protocol&lt;/a&gt; for real-time and persistent connections between a server and one or more client(s). This protocol is faster than standard HTTP connections, allows for a two-way back-and-forth transfer of data between server and clients. Initialized with a HTTP upgrade request as a handshake operation, after which all parties, server and clients, may send data at any time, from either direction, at any time. Generally used for applications such as social feeds, chat clients, multiplayer games, multimedia streaming, and collaborative development sessions.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Why GoLang?
&lt;/h3&gt;

&lt;p&gt;Concurrency, the biggest advantage to our use-case, socket programming, given it's asynchronous design. Along with the fact that GoLang is an extremely modern high-level language making development of established applications quick and efficient. Plus I just love the simplistic elegance of the language! :) Don't know GoLang? Well, this is a great low-level project to see some basic concepts at play, especially goroutines, GoLang's concurrency feature.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Project Start
&lt;/h3&gt;

&lt;p&gt;This tutorial is based off of my open-source &lt;a href="https://github.com/Alice-Williams-Tech/go-sockets/tree/v0.1.0"&gt;repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Create a new project folder and initialize a new git repository to track changes, even if only stored locally by opening a shell or command-line window within your new project folder and running, &lt;code&gt;git init&lt;/code&gt;. Make two sub-folders in your project folder, for the server and client. Initialize a GoLang module in each folder by running, &lt;code&gt;go mod init&lt;/code&gt;, within each folder, you may need to supply the path if you're outside of your GOPATH. Create two new files, each called, &lt;code&gt;main.go&lt;/code&gt;, as the application entry-points, inside of each sub-folder.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Socket Server
&lt;/h3&gt;

&lt;p&gt;The 'Hello World' step:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "fmt"
)

const (
    connHost = "localhost"
    connPort = "8080"
    connType = "tcp"
)

func main() {
    fmt.Println("Starting " + connType + " server on " + connHost + ":" + connPort)

}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Listening and the main loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "fmt"
    "os"
    "net"
)

const (
    connHost = "localhost"
    connPort = "8080"
    connType = "tcp"
)

func main() {
    fmt.Println("Starting " + connType + " server on " + connHost + ":" + connPort)
    l, err := net.Listen(connType, connHost+":"+connPort)
    if err != nil {
        fmt.Println("Error listening:", err.Error())
        os.Exit(1)
    }
    defer l.Close()

    for {

    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Accept client connections:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "fmt"
    "os"
    "net"
)

const (
    connHost = "localhost"
    connPort = "8080"
    connType = "tcp"
)

func main() {
    fmt.Println("Starting " + connType + " server on " + connHost + ":" + connPort)
    l, err := net.Listen(connType, connHost+":"+connPort)
    if err != nil {
        fmt.Println("Error listening:", err.Error())
        os.Exit(1)
    }
    defer l.Close()

    for {
        c, err := l.Accept()
        if err != nil {
            fmt.Println("Error connecting:", err.Error())
            return
        }
        fmt.Println("Client connected.")

        fmt.Println("Client " + c.RemoteAddr().String() + " connected.")
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Handling clients concurrently:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "bufio"
    "fmt"
    "log"
    "net"
    "os"
)

const (
    connHost = "localhost"
    connPort = "8080"
    connType = "tcp"
)

func main() {
    fmt.Println("Starting " + connType + " server on " + connHost + ":" + connPort)
    l, err := net.Listen(connType, connHost+":"+connPort)
    if err != nil {
        fmt.Println("Error listening:", err.Error())
        os.Exit(1)
    }
    defer l.Close()

    for {
        c, err := l.Accept()
        if err != nil {
            fmt.Println("Error connecting:", err.Error())
            return
        }
        fmt.Println("Client connected.")

        fmt.Println("Client " + c.RemoteAddr().String() + " connected.")

        go handleConnection(c)
    }
}

func handleConnection(conn net.Conn) {
    buffer, err := bufio.NewReader(conn).ReadBytes('\n')

    if err != nil {
        fmt.Println("Client left.")
        conn.Close()
        return
    }

    log.Println("Client message:", string(buffer[:len(buffer)-1]))

    conn.Write(buffer)

    handleConnection(conn)
}

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Testing without a client:&lt;/p&gt;

&lt;p&gt;If you're developing on Linux you can test your new socket server application without writing the client application first. Start your socket server with, &lt;code&gt;go run main.go&lt;/code&gt;, from the server sub-folder within your shell. Now run, &lt;code&gt;nc localhost 8080&lt;/code&gt;, replacing the host and port number if needed. There are applications to run the nc (netcat) command on Windows, however, I don't know the best of options here.&lt;/p&gt;



&lt;h3&gt;
  
  
  Socket Client
&lt;/h3&gt;

&lt;p&gt;The 'Hello World' step:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "fmt"
)

const (
    connHost = "localhost"
    connPort = "8080"
    connType = "tcp"
)

func main() {
    fmt.Println("Connecting to " + connType + " server " + connHost + ":" + connPort)
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Connecting to the server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "fmt"
)

const (
    connHost = "localhost"
    connPort = "8080"
    connType = "tcp"
)

func main() {
    fmt.Println("Connecting to " + connType + " server " + connHost + ":" + connPort)
}
    conn, err := net.Dial(connType, connHost+":"+connPort)
    if err != nil {
        fmt.Println("Error connecting:", err.Error())
        os.Exit(1)
    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Handling input and relaying response:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "fmt"
)

const (
    connHost = "localhost"
    connPort = "8080"
    connType = "tcp"
)

func main() {
    fmt.Println("Connecting to " + connType + " server " + connHost + ":" + connPort)Getting Started with Sockets in GoLang
}
    conn, err := net.Dial(connType, connHost+":"+connPort)
    if err != nil {
        fmt.Println("Error connecting:", err.Error())
        os.Exit(1)
    }
    reader := bufio.NewReader(os.Stdin)

    for {
        fmt.Print("Text to send: ")

        input, _ := reader.ReadString('\n')

        message, _  := bufio.NewReader(conn).ReadString('\n')

        log.Print("Server relay:", message)
    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Testing the client:&lt;/p&gt;

&lt;p&gt;Run your socket server with, &lt;code&gt;go run main.go&lt;/code&gt;, from the server project sub-folder on your shell or command-line. Now open another shell or command-line session within the client folder and run, &lt;code&gt;go  run main.go&lt;/code&gt; here as well to start the client application. Any text entered into the client will be sent to the server, displayed with a timestamp, and relayed back, being displayed again.&lt;/p&gt;

&lt;p&gt;This tests the basic functionality of the socket server-client interface and can be extended upon by expanding the server.go handleConnection function. Each client is handled concurrently by the server and as many clients may connect as your system can handle running, you may also connect through other local systems or over the internet if you expose the port to traffic.&lt;/p&gt;

&lt;h3&gt;
  
  
  Wrapping up
&lt;/h3&gt;

&lt;p&gt;Well now you have stand-alone socket server and client interfaces, in pure standard-library GoLang! So what's next you ask? The sky's the limit, write an IRC-style chat client or a streaming application, just take it one step at a time, and that's one reason we started with a new git repository to manage all those changes you'll start adding.&lt;/p&gt;

&lt;p&gt;My open-source Github &lt;a href="https://github.com/Alice-Williams-Tech/go-sockets/tree/v0.1.0"&gt;repository&lt;/a&gt; the code for this tutorial is stored in has further line-by-line documentation.&lt;br&gt;
&lt;br&gt;&lt;br&gt;
All The Best and Happy Coding!&lt;br&gt;
By, &lt;em&gt;Alice Williams&lt;/em&gt;&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>tutorial</category>
      <category>go</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Raspberry Pi 4 Model B 8GB - Dev Workstation - Performance &amp; Review</title>
      <dc:creator>Alice Williams</dc:creator>
      <pubDate>Wed, 15 Jul 2020 03:13:17 +0000</pubDate>
      <link>https://forem.com/alicewilliamstech/raspberry-pi-4-model-b-8gb-dev-workstation-performance-review-4b12</link>
      <guid>https://forem.com/alicewilliamstech/raspberry-pi-4-model-b-8gb-dev-workstation-performance-review-4b12</guid>
      <description>&lt;h1&gt;
  
  
  Raspberry Pi 4 Model B 8GB - Dev Workstation - Performance &amp;amp; Review
&lt;/h1&gt;



&lt;h3&gt;
  
  
  The Computer:
&lt;/h3&gt;

&lt;p&gt;Single-board computers, what I'd once personally brushed off and completely ignored as little more than a child's learning toy, has now completely replaced my Windows 10 laptop with WSL2 for everything from software development to general usage: from web browsing to checking my email, from debugging my latest project &lt;a href="https://github.com/Alice-Williams-Tech/go-sockets"&gt;shameless plug&lt;/a&gt; to resizing images. This little computer has really impressed me, especially since overclocking the quad-core CPU from a meager 1.5GHz to a still stable 2.0GHz!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7z-N-02x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/v0wj3dw9fcct9hoeaixw.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7z-N-02x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/v0wj3dw9fcct9hoeaixw.jpg" alt="Raspberry Pi 4 Model B in White Case"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With the case, fan, and heat-sinks the cooling has been no issue whatsoever and the computer runs with the same steady purr for a week straight with no noticeable drop off or change in performance. Be it the lightweight Linux system, nature of single-board systems, or state of modern computing but I find that rather impressive considering that computers in the past would get memory leaks or crash after just hours of up-time.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Performance:
&lt;/h3&gt;

&lt;p&gt;Unfortunately the 64-bit version of the OS it ships with, Rasberry OS or formerly Raspbian, a Debian distribution, is still in beta development. However, with the 32-bit version of Rasberry OS Lite, along with a window manager and desktop environment, I've managed to run upon the most stable and light-weight system I've ever worked with to date and it rarely idles above 1GB of ram usage, even after I left it idling for a week to test for memory leaks! It can handle Chrome and even has support for VS Code via a &lt;a href="http://code.headmelted.com/"&gt;community project&lt;/a&gt;, has support for image editing through an &lt;a href="https://pinta-project.com/pintaproject/pinta/"&gt;open-source project&lt;/a&gt;, 3D modeling even with &lt;a href="https://www.tomshardware.com/news/raspberry-pi-3d-modeling-blender-how"&gt;Blender&lt;/a&gt;! Plus office support through nothing else but &lt;a href="https://www.libreoffice.org/get-help/install-howto/linux/"&gt;Libre Office&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ITdfdd_---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a524orf6apbmyassz3oa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ITdfdd_---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a524orf6apbmyassz3oa.png" alt="Resource Monitor showing current performance"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are some occasional slow-downs or catches, generally when the window browser grows cluttered and multiple applications are running like VS Code and Libre Office, however, in those scenarios there is almost always something I can close down to bring the system back to a reasonable speed. Surprisingly it's amazingly plug-and-play as well and getting started with the system took less than thirty minutes flat, and has given me no trouble whatsoever with any devices whatsoever.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion:
&lt;/h3&gt;

&lt;p&gt;For a Linux workstation, primarily for development and related needs, this smol device has been incredibly more than I expected, I'd highly recommend it and have already ordered two more for use as other devices in my home. The guide I followed to get the Raspberry Lite OS along with a window manager and desktop environment can be found &lt;a href="https://www.raspberrypi.org/forums/viewtopic.php?t=133691"&gt;here&lt;/a&gt;, it's definitely worth taking a glance at as they do a very detailed benchmark of various environment setups and their performances. Various options are available from headless environments to full or lite versions of OS's, if anyone out there has OS recommendations or is running something particularly suited to the device please do reach out!&lt;/p&gt;

&lt;p&gt;Never in my life did I think I'd consider replacing what I once used an entire full-sized desktop computer for with a computer that is the size of my wallet. It really shows how far computers have come over time and I'm really looking forward to trying out other single-board computers out there!&lt;br&gt;
&lt;br&gt;&lt;br&gt;
All The Best and Happy Tinkering!&lt;br&gt;
By, &lt;em&gt;Alice Williams&lt;/em&gt;&lt;/p&gt;

</description>
      <category>raspberrypi</category>
      <category>hardware</category>
    </item>
  </channel>
</rss>
