Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
SocketIO and TypeScript
Highest Rated
Rating: 4.6 out of 5(95 ratings)
826 students

SocketIO and TypeScript

Learn SocketIO, TypeScript and NodeJS To Create Multiplayer Realtime Interactive Content for the Web
Created bySean Bradley
Last updated 5/2024
English
English [Auto],

What you'll learn

  • TSC and tsconfig for browsers and NodeJS environments
  • Setup Nodemon and Concurrently
  • NPM, NodeJS and package json
  • Understand SocketIO communications between the Server and Clients while writing it all in TypeScript
  • Build some example use cases, such as a chat, collaborative painter and integrate into Threejs
  • Learn about Express and serving static content through NodeJS
  • Learn how to build robust and interactive applications using TypeScript and SocketIO
  • Provision and Deploy to a cloud server, Setup Nginx proxy, Point a Domain Name and Add SSL

Course content

1 section30 lectures2h 52m total length
  • Introduction3:14

    The course is in 5 main sections,

    1. Set up the Development Environment

    2. Create a Socket.IO boilerplate project - This section is optional, but advisable. This will give you a very good understanding of the aspects involved in creating a brand-new Socket.IO application from scratch.

    3. Install Socket.IO Course Boilerplate - This section is also optional, but is useful in case you by-passed section 2, or you have finished the course, and you want a familiar template project that you can start from.

    4. Learn all about the many aspects of Socket.IO from the core up to using it in more advanced examples and involving other third party libraries.

    5. Deploying to Production - We will look at several options that you have for hosting your own Socket.IO projects on the internet.

  • Setup Development Environment2:14

    To create a development environment like mine, install these packages.

    1. VSCode : https://code.visualstudio.com/

    2. NodeJS : https://nodejs.org/

  • Create Socket.IO Boilerplate6:31

    Over the next few lessons, we will set up the course boilerplate.

  • Create the Socket.IO Server8:30

    We are going to create, compile and start a simple Socket.IO server.

  • Compile using tsconfig.json6:25

    We can simplify the transpiling process by using a tsconfig.json

  • TSC Watch, Nodemon and Concurrently8:49

    Manually recompiling and restarting the NodeJS server upon each change to the code can become tedious. So we look at the option of automating the recompilation and server restarting using tsc watch option, nodemon and concurrently.

  • Create the SocketIO Client8:24
  • Build the Client using TSC7:14

    In this lesson, I show how to use TSC in watch mode, to create the ./dist/client.js script from the client TypeScript source code.

    Note that this version will use an importmap to tell the browser where it can find the socket.io-client library when it encounters it in the ES6 import statement present in the transpiled client.js.

  • Build the Client using Webpack8:35

    In this lesson, I show how to use Webpack, to create the ./dist/bundle.js script from the client TypeScript source code.

    This solution is best when your client application becomes,

    • larger and more sophisticated,

    • references one or more external JavaScript modules,

    • you want to bundle all the client scripts into one,

    • benefit from using HMR while developing,

    • benefit from tree shaking for modules that support it.

  • Socket.IO TypeScript Boilerplate3:45

    This section is optional. If you completed all the sections before this, then you already have the project created. This boilerplate is useful if you have chosen to bypass all the preceding sections, or you got stuck, or you have already finished the course, and you would like to use a Three.js TypeScript project template that you are familiar with.

  • Communicating Between Server and Clients0:52

    Common Use Cases and there Relevant Events and Methods

  • Server Connection and Disconnect Events4:29

    We look at server side Socket.IO connection and disconnection events and see how we can utilise them.

  • Server Socket Emit5:23

    When a new socket object is created from a connection server side, we can use that socket anytime, to send a message to the connected client.

  • Server Socket Broadcast2:27

    Broadcast a message to all other connected sockets except for itself. Used most often after a socket level event occurs. E.g., a new message has arrived from an existing client socket, and you want to relay it onto all the other clients.

  • Server IO Emit2:34

    Emit a message to all connected sockets.

    Used most often when a server level event occurs. E.g., a timer event occurred, and you want to send a message to all clients.

  • Server Emit to Specific Socket8:14

    Using IO to emit a message to a specific socket ID.

  • Client Connect and Disconnect Events1:27

    We now look at the client side connect and disconnect events.

  • Client Emit4:15

    It is also possible, for the client to initiate a message to the server at any time. In this example, we will prompt the client for a username, and then pass it to the server.

  • Simple Chat10:24

    Creating a simple chat client and server.

  • Collaborative Painter3:29

    A basic collaborative painting example.

  • Multiplayer Threejs16:47

    Implementing multiplayer functionality into a threejs third person view application.

  • Namespaces5:59

    It is possible to have one socket server, and have several types of clients connect to it.

    To separate command listeners for different types of applications, connecting to the one socket server, you can use namespaces.

    Note that the default namespace when connecting to a Socket.IO server will be "/".

    const socket = io()

    Is the same as,

    const socket = io('/')

    If you wanted the one socket server, to deliver random numbers, and also run the collaboration painter program, then the namespaces you could set up may be rng and colabPainter.

  • Deploying to Production1:45

    We will now deploy one of the examples to a production server on the internet.

    Steps are,

    • Set up the Webpack Production Script

    • Provision a Cloud Server for Production

    • Deploy Files to the Server

    • Start the Example on the server

    • Set up an Nginx Proxy

    • Set up and Point a Domain Name

    • Install an SSL certificate

    At the end, our example code, developed using TypeScript, will be officially on the internet for the public to see.

  • Set up the Webpack Production Script5:02

    We have been using the webpack.dev.js file during each lesson so far.

    The Webpack-Dev-Server is dynamically generating a bundle.js at runtime for us that is also running in HMR mode.

    This bundle.js is generated fast, and we can preview it right away in the browser. However, it is a very large file in comparison to a production specific version of bundle.js.

    We will use Webpack to generate the production specific version of bundle.js.

    The production build won't include the extra code used by the HMR option since we won't be developing directly in our production environment.

    Now, while the production version of bundle.js is much smaller, it does take quite a lot longer to generate, so it is not as beneficial to use it in development since you will need to wait some extra time between each change before you can preview it.

    The production version of bundle.js will also be saved as a new file directly to the file system, so then we can copy it manually later to our own production web servers.

  • Provision a Cloud Server for Production3:19

    I want a publicly accessible server on the internet so that I can share my examples with my friends.

  • Deploy Files to the Server6:24

    We will connect to our server using Putty SSH, and deploy the files to our server using WinSCP SFTP.
    We also install NPM on our server.

  • Start Production6:25

    Navigate into the folder that contains the package.json

    $ cd /var/www/socketio-example


    Now, install the packages from the package.json by using the command,

    $ npm install --omit=dev


    Now, you can start the Mini Games server.

    $ npm start


    Now open a browser and visit http://[your ip address]:3000

  • Install Nginx Proxy10:46

    I also want to point a domain name and an SSL certificate to the games server. We can add settings inside our server.js which is being run by NodeJS to manage this, but it is very common to use a proxy instead for this purpose. We can use Nginx. Nginx will be able to manage proxying for all your domain names and SSL certificates for this server if you had several websites running on it.

  • Point a Domain Name3:51

    I have a domain already, and I can add subdomains to it, so I will create a new subdomain, socketio-example.sbcode.net

    In my domain name provider, I will create a new A name record called socketio-example for my main domain sbcode.net that points to the IP address of the new server.

  • Add SSL5:14

    Let's make http://socketio-example.your-domain.tld have an SSL certificate and redirect all HTTP traffic to HTTPS

Requirements

  • Desire to learn about websockets using SocketIO
  • Access to a PC, Mac or Linux with ability to install software such as VSCode, Git and NodeJS
  • Having some basic experience with HTML, CSS and JavaScript desirable

Description

Welcome to my course on SocketIO and TypeScript where you will learn how to create multiplayer real-time interactive content that runs in the browser and on the web.

We will start by creating a sophisticated boilerplate that contains both client and server components.

When finished, any development we do will auto compile and restart the server and client applications with the latest changes.

We will then learn each of the concepts involved in initiating communications over sockets from both the client and server perspectives.

After that, we will look at several use cases for using sockets on the web and understand how to integrate SocketIO into these types of applications.

Next, we will learn how to deploy our finished applications to a live web server, configure a domain name and SSL, and configure the web server to correctly communicate using the web sockets protocol.

At the end of the course, you would have built several types of SocketIO applications and understand how real-time interactive content works in the browser.

So if you know that you like coding, you like seeing it work for yourself, you like to experiment, and have millions of ideas that you want to achieve, then this course is for you.

Thanks for taking part in my course, and I hope to see you there.

Who this course is for:

  • Beginner Coders
  • People interested in SocketIO and TypeScript
  • People interested in creating real-time interactive multiplayer games