How to Use WebSockets in Unreal Engine



How to Use WebSockets in Unreal Engine

How to Use WebSockets in Unreal Engine

Download Core to create games for FREE: https://bit.ly/Core-Flopperam
Join the Game Creator Challenge: https://itch.io/jam/gcc

In this video, we go over how to use the WebSockets module in an Unreal Engine game. The WebSockets module includes only client functionality. Therefore, we use the module to establish a connection between Unreal clients and a sample NodeJS server, send and receive messages over that connection, and close that connection. Since the WebSockets module is not natively exposed to blueprints, we wrote some C++ code in the GameInstance and Character classes in order to not only connect to and disconnect from a server but also send messages to the server and implement event handlers in the IWebSocket interface. At the end of the video, we test multiple packaged clients simultaneously by having them all connect to the same server and send messages to each other via WebSockets.

*****IMPORTANT LINKS*****
More information about the WebSocket protocol: https://en.wikipedia.org/wiki/WebSocket
Unreal Engine project code that was used in this video: https://github.com/chris-gong/websocket-client-example-ue5
Node.js WebSocket server code that was used in this video: https://github.com/chris-gong/ws-server-example-nodejs
Download and install NodeJs: https://nodejs.org/en/download/
Download and install Git: https://git-scm.com/downloads
How to expose C++ code to blueprints: https://docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/Blueprints/TechnicalGuide/ExtendingBlueprints/
Cool things you can make with WebSocket: https://medium.com/the-developer-journal/10-most-amazing-use-cases-of-websockets-go-real-time-166b71e0e711
Unreal Engine API Reference for the WebSockets module: https://docs.unrealengine.com/en-US/API/Runtime/WebSockets/

*****IMPORTANT COMMANDS*****
cd [directory-path]
cd “[path-with-spaces]”
git clone https://github.com/chris-gong/ws-server-example-nodejs.git
npm install
node server
To end the server: Ctrl-C
Windows: cls
Linux: clear
WebSocketTest.exe -WINDOWED
To fit make a window to take up either half or a quarter of the screen on Windows: Windows key + any arrow key

How to support the channel:
Get a shirt or sweatshirt with free shipping (Use code “SHIP” at checkout): https://teespring.com/stores/flopperam
Become a member: https://www.youtube.com/channel/UCO77KLKwplncMHLo6gLpIHw/join
Support us on Patreon: https://www.patreon.com/flopperam
Donate to our PayPal: https://www.paypal.me/flopperam
Sponsor us on Github: https://github.com/sponsors/chris-gong

Social media links:
Discord: https://discord.gg/8yvTRBv
Twitter: https://twitter.com/Flopperam
Instagram: https://www.instagram.com/flopperam/
Facebook: https://www.facebook.com/flopperam

0:00 Intro
1:09 Sponsor
2:33 Creating a WebSocket connection
10:04 Adding WebSocket event handlers
14:34 Sending data from client to server
18:10 Testing with multiple packaged clients simultaneously
20:40 Outro

#unrealengine #websocket #ue5

Comments are closed.