Minecraft lets you connect to a websocket server when you’re in a game. The server can receive and send any commands. This lets you build a bot that you can … (well, I don’t know what it can do, let’s explore.)
Minecraft hascommandsyou can type on a chat window. For example, type/
to start a command and typesetblock ~1 ~0 ~0 grass
changes the block 1 north of you into grass. (~
means relative to you. Coordinates are specified as X, Y and Z.)

Note: These instructions were tested on Minecraft Bedrock 1.16. I haven’t tested them on the Java Edition.
Connect to Minecraft
You can send any command to Minecraft from a websocket server. Let’s use JavaScript for this.
First, runnpm install ws uuid
. (We needws
for websockets anduuid
to generate unique IDs.)
Then create thismineserver1.js
:
const WebSocket = require('ws')const uuid = require('uuid') // For later use// Create a new websocket server on port 3000console.log('Ready. On MineCraft chat, type /connect localhost:3000')const wss = new WebSocket.Server({ port: 3000 })// On Minecraft, when you type "/connect localhost:3000" it creates a connectionwss.on('connection', socket => { console.log('Connected')})
On Minecraft > Settings > General > Profile, turn off the “Require Encrypted Websockets” setting.

Runnode mineserver1.js
. Then type/connect localhost:3000
in a Minecraft chat window. You’ll see 2 things:
- MineCraft says “Connection established to server: ws://localhost:3000”
- Node prints “Connected”
Now, our program is connected to Minecraft, and can send/receive messages.

Notes:
- The Python equivalent is inmineserver1.py. Run
python mineserver1.py
. - If you get an
Uncaught Error: Cannot find module 'ws'
, make sure you rannpm install ws uuid
. - If you get an “Encrypted Session Required” error, make sure you turned off the “Require Encrypted Websockets” setting mentioned above.
- To disconnect, run
/connect off
Subscribe to chat messages
Now let’s listen to the players’ chat.
A connected websocket server can send a “subscribe” message to Minecraft saying it wants to “listen” to specific actions. For example, you can subscribe to “PlayerMessage”. Whenever a player sents a chat message, Minecraft will notify the websocket client.
Here’s how to do that. Add this code in thewss.on('connection', socket => { ... })
function.
// Tell Minecraft to send all chat messages. Required once after Minecraft starts socket.send(JSON.stringify({ "header": { "version": 1, // We're using the version 1 message protocol "requestId": uuid.v4(), // A unique ID for the request "messageType": "commandRequest", // This is a request ... "messagePurpose": "subscribe" // ... to subscribe to ... }, "body": { "eventName": "PlayerMessage" // ... all player messages. }, }))
Now, every time a player types something in the chat window, the socket will receive it. Add this code below the above code:
// When MineCraft sends a message (e.g. on player chat), print it. socket.on('message', packet => { const msg = JSON.parse(packet) console.log(msg) })
This code parses all the messages it receives and prints them.
This code in ismineserver2.js
. Runnode mineserver2.js
. Then type/connect localhost:3000
in a Minecraft chat window. Then type a message (e.g. “alpha”) in the chat window. You’ll see a message like this in the console.
{ header: { messagePurpose: 'event', // This is an event requestId: '00000000-0000-0000-0000-000000000000', version: 1 // using version 1 message protocol }, body: { eventName: 'PlayerMessage', measurements: null, properties: { AccountType: 1, ActiveSessionID: 'e0afde71-9a15-401b-ba38-82c64a94048d', AppSessionID: 'b2f5dddc-2a2d-4ec1-bf7b-578038967f9a', Biome: 1, // Plains Biome. https://minecraft.gamepedia.com/Biome Build: '1.16.201', // That's my build BuildNum: '5131175', BuildPlat: 7, Cheevos: false, ClientId: 'fcaa9859-0921-348e-bc7c-1c91b72ccec1', CurrentNumDevices: 1, DeviceSessionId: 'b2f5dddc-2a2d-4ec1-bf7b-578038967f9a', Difficulty: 'NORMAL', // I'm playing on normal difficulty Dim: 0, GlobalMultiplayerCorrelationId: '91967b8c-01c6-4708-8a31-f111ddaa8174', Message: 'alpha', // This is the message I typed MessageType: 'chat', // It's of type chat Mode: 1, NetworkType: 0, Plat: 'Win 10.0.19041.1', PlayerGameMode: 1, // Creative. https://minecraft.gamepedia.com/Commands/gamemode Sender: 'Anand', // That's me. Seq: 497, WorldFeature: 0, WorldSessionId: '8c9b4d3b-7118-4324-ba32-c357c709d682', editionType: 'win10', isTrial: 0, locale: 'en_IN', vrMode: false } }}
Notes:
- The Python equivalent is inmineserver2.py. Run
python mineserver2.py
. - The official Minecraft docs say that theMCWSS protocol is outdated. But it seems to work.
- The full list of things we can subscribe to is undocumented, but@jocopa3has reverse-engineered alist of messageswe can subscribe to, and they’re somewhat meaningful.
- This Go packagehas code that explores theprotocolfurther.
- Thischathas more details. There’s also anoutdated list of JSON messagesfrom@jocopa3.
- Here’s a sample program thatplaces a block in Minecraft
Build structures using chat
Let’s create a pyramid of size10
around us when we typepyramid 10
in the chat window.
The first step is to check if the player sent a chat message likepyramid 10
(or another number). Add this code below the above code:
// When MineCraft sends a message (e.g. on player chat), act on it. socket.on('message', packet => { const msg = JSON.parse(packet) // If this is a chat window if (msg.body.eventName === 'PlayerMessage') { // ... and it's like "pyramid 10" (or some number), draw a pyramid const match = msg.body.properties.Message.match(/^pyramid (\d+)/i) if (match) draw_pyramid(+match[1]) } })
If the user types “pyramid 3” on the chat window,draw_pyramid(3)
is called.
Indraw_pyramid()
, let’s send commands to build a pyramid. To send a command, we need to create a JSON with the command (e.g.setblock ~1 ~0 ~0 grass
). Add this code below the above code:
function send(cmd) { const msg = { "header": { "version": 1, "requestId": uuid.v4(), // Send unique ID each time "messagePurpose": "commandRequest", "messageType": "commandRequest" }, "body": { "version": 1, // TODO: Needed? "commandLine": cmd, // Define the command "origin": { "type": "player" // Message comes from player } } } socket.send(JSON.stringify(msg)) // Send the JSON string }
Let’s writedraw_pyramid()
to create a pyramid using glowstone by adding this code below the above code:
// Draw a pyramid of size "size" around the player. function draw_pyramid(size) { // y is the height of the pyramid. Start with y=0, and keep building up for (let y = 0; y < size + 1; y++) { // At the specified y, place blocks in a rectangle of size "side" let side = size - y; for (let x = -side; x < side + 1; x++) { send(`setblock ~${x} ~${y} ~${-side} glowstone`) send(`setblock ~${x} ~${y} ~${+side} glowstone`) send(`setblock ~${-side} ~${y} ~${x} glowstone`) send(`setblock ~${+side} ~${y} ~${x} glowstone`) } } }
This code in ismineserver3.js
.
- Run
node mineserver3.js
. - Then type
/connect localhost:3000
in a Minecraft chat window. - Then type
pyramid 3
in the chat window. - You’ll be surrounded by a glowstone pyramid.

Notes:
- The Python equivalent is inmineserver3.py. Run
python mineserver3.py
. - The “requestId” needs to be a UUID — at least for block commands. I tried unique “requestId” values like 1, 2, 3 etc. That didn’t work.
Understand Minecraft’s responses
For every command you send, Minecraft sends a response. It’s “header” looks like this:
{ "header": { "version": 1, "messagePurpose": "commandResponse", // Response to your command "requestId": "97dee9a3-a716-4caa-aef9-ddbd642f2650" // ... and your requestId }}
If the command is successful, the response hasbody.statusCode == 0
. For example:
{ "body": { "statusCode": 0, // No error "statusMessage": "Block placed", // It placed the block you wanted "position": { "x": 0, "y": 64, "z": 0 } // ... at this location },}
If the command failed, the response has a negativebody.statusCode
. For example:
{ "body": { "statusCode": -2147352576, // This is an error "statusMessage": "The block couldn't be placed" },}
To print these, add this tosocket.on('message', ...)
:
// If we get a command response, print it if (msg.header.messagePurpose == 'commandResponse') console.log(msg)
This code in ismineserver4.js
.
- Run
node mineserver4.js
. - Then type
/connect localhost:3000
in a Minecraft chat window. - Then type
pyramid 3
in the chat window. - You’ll be surrounded by a glowstone pyramid, and theconsole will show every command response.
Notes on common error messages:
The block couldn't be placed
(-2147352576): The same block was already at that location.Syntax error: Unexpected "xxx": at "~0 ~9 ~-1 >>xxx<<"
(-2147483648): You gave wrong arguments to the command.Too many commands have been requested, wait for one to be done
(-2147418109): Minecraft only allows 100 commands can be executed without waiting for their response.- More error messages here.
Wait for commands to be done
Typing “pyramid 3” works just fine. But try “pyramid 5” and your pyramid is incomplete.

That’s because Minecraft only allows up to 100 messages in its queue. On the 101st message, you get aToo many commands have been requested, wait for one to be done
error.
{ "header": { "version": 1, "messagePurpose": "error", "requestId": "a5051664-e9f4-4f9f-96b8-a56b5783117b" }, "body": { "statusCode": -2147418109, "statusMessage": "Too many commands have been requested, wait for one to be done" }}
So let’s modifysend()
to add to a queue and send in batches. We’ll create two queues:
const sendQueue = [] // Queue of commands to be sent const awaitedQueue = {} // Queue of responses awaited from Minecraft
Inwss.on('connection', ...)
, when Minecraft completes a command, we’ll remove it from theawaitedQueue
. If the command has an error, we’ll report it.
// If we get a command response if (msg.header.messagePurpose == 'commandResponse') { // ... and it's for an awaited command if (msg.header.requestId in awaitedQueue) { // Print errors 5(if any) if (msg.body.statusCode < 0) console.log(awaitedQueue[msg.header.requestId].body.commandLine, msg.body.statusMessage) // ... and delete it from the awaited queue delete awaitedQueue[msg.header.requestId] } } // Now, we've cleared all completed commands from the awaitedQueue.
Once we’ve processed Minecraft’s response, we’ll send pending messages fromsendQueue
, upto 100 and add them to theawaitedQueue
.
// We can send new commands from the sendQueue -- up to a maximum of 100. let count = Math.min(100 - Object.keys(awaitedQueue).length, sendQueue.length) for (let i = 0; i < count; i++) { // Each time, send the first command in sendQueue, and add it to the awaitedQueue let command = sendQueue.shift() socket.send(JSON.stringify(command)) awaitedQueue[command.header.requestId] = command } // Now we've sent as many commands as we can. Wait till the next PlayerMessage/commandResponse
Finally, in function send(), instead ofsocket.send(JSON.stringify(msg))
, we usesendQueue.push(msg)
to add the message to the queue.
This code in ismineserver5.js
.
- Run
node mineserver5.js
. - Then type
/connect localhost:3000
in a Minecraft chat window. - Then type
pyramid 6
in the chat window. - You’ll be surrounded by a large glowstone pyramid.
- The console will print messages like
setblock ~0 ~6 ~0 glowstone The block couldn't be placed
because we’re trying to place duplicate blocks.

FAQs
Does Minecraft use WebSockets? ›
Minecraft has websocket connection commands that may be used to connect to a websocket server. These commands are /connect and /wsserver . Both these commands have the same effect. Once connected to a websocket, the connection will last until the server closes it or until the player completely exits the game.
What is WSS Minecraft? ›Stands for "WebSocket server". Used to connect to a WebSocket server which uses command messages to communicate with clients. Used primarily in Education Edition. The alias /connect can also be used.
Is it safe to use WebSockets? ›WSS is secure, so it prevents things like man-in-the-middle attacks. A secure transport prevents many attacks from the start. In conclusion, WebSockets aren't your standard socket implementation. WebSockets are versatile, the established connection is always open, and messages can be sent and received continuously.
How do I make my own server on Minecraft? ›- Verify the Latest Version of Java. ...
- Download Minecraft_Server. ...
- Save as a Batch File to Run Server. ...
- Agree to the EULA. ...
- Launch Your Server. ...
- Join Your Server. ...
- Forward Your Ports. ...
- Find Your External IP Address.
/connect or /wsserver is a command in that allows the player to connect the world to a websocket server, the command is working for normal single player but the command is non existent on the dedicated server.
How do you use the Videostream command in Minecraft? ›How to use /wsserver command in Minecraft PE (BE) - YouTube
How do I create a secure WebSocket? ›- #0: Enable CORS. WebSocket doesn't come with CORS inbuilt. ...
- #1: Implement rate limiting. Rate limiting is important. ...
- #2: Restrict payload size. ...
- #3: Create a solid communication protocol. ...
- #4: Authenticate users before WS connection establishes. ...
- #5: Use SSL over websockets. ...
- Questions?
Navigate to “Settings.” Select “Network.” Select “View Connection Status.” In the “View Connection Status” menu, you'll see your server address under “IP Address.”
Can WebSockets be hacked? ›Some WebSockets security vulnerabilities arise when an attacker makes a cross-domain WebSocket connection from a web site that the attacker controls. This is known as a cross-site WebSocket hijacking attack, and it involves exploiting a cross-site request forgery (CSRF) vulnerability on a WebSocket handshake.
Are WebSockets faster than HTTP? ›All the frequently updated applications used WebSocket because it is faster than HTTP Connection. When we do not want to retain a connection for a particular amount of time or reuse the connection for transmitting data; An HTTP connection is slower than WebSockets.
Who invented WebSocket? ›
WebSocket was first referenced as TCPConnection in the HTML5 specification, as a placeholder for a TCP-based socket API. In June 2008, a series of discussions were led by Michael Carter that resulted in the first version of the protocol known as WebSocket.
What are the best Minecraft bedrock servers? ›NetherGames. Nethergames is probably the most well-known Minecraft Bedrock server. It's no surprise that Nethergames is popular because it has a variety of game modes, some of which get ignored everywhere else, such as Creative Plots, Factions, Murder Mystery, Skywars, Bedwars, Duels, and Skyblock.
What is Web socket server? ›A WebSocket server is nothing more than an application listening on any port of a TCP server that follows a specific protocol. The task of creating a custom server tends to scare people; however, it can be straightforward to implement a simple WebSocket server on your platform of choice.
Can I turn my Minecraft world into a server? ›Go in to your Minecraft folder ( %appdata%\. minecraft ), then open the saves folder. In there, all your Singleplayer worlds are saved. Now select the Singleplayer world that you want to use for your Multiplayer Server, and drag it into your Minecraft Server folder.
Are Minecraft servers free? ›Many server experiences and minigames are completely free, but if you want to unlock special events or games, show off with unique skins or chat flair, or unlock some surprise content with mystery boxes, you'll need a handful of Minecraft Coins.
Is making a Minecraft server free? ›You can create your own private server on Minecraft Java edition using free server software provided by Mojang. You can download this through the Minecraft website, but the initial process and how to run your server needs some more explaining.
How do you code bedrock mods in Minecraft? ›How To Make Mods/Addons IN Minecraft Bedrock Edition [EP1]
Is WebSocket a protocol? ›1.7.
The WebSocket protocol is an independent TCP-based protocol. Its only relationship to HTTP is that its handshake is interpreted by HTTP servers as an Upgrade request. By default the WebSocket protocol uses port 80 for regular WebSocket connections and port 443 for WebSocket connections tunneled over TLS [RFC2818].
You can use the /say command to send a public message to all players in a Minecraft world (see also /msg, /tell or /w for private message).
How do I protect my Minecraft server from DDoS? ›- Step 1: Backend Setup. Setup Minecraft on your server, this server will be from here on referred to as the "backend server". ...
- Step 2: Purchase DDoS Protection Service. ...
- Step 3: Encapsulation Setup (Optional) ...
- Step 4: Add Ports. ...
- Step 5: Finish & Test.
How do you write messages in Console Minecraft? ›
You can use the /msg command to send a private message to a player or group of players in Minecraft (see also /tell or /w for private message, see /say for public message).
Are WebSockets still used? ›Websockets are largely obsolete because nowadays, if you create a HTTP/2 fetch request, any existing keepalive connection to that server is used, so the overhead that pre-HTTP/2 XHR connections needed is lost and with it the advantage of Websockets.
Can WebSocket use HTTPS? ›You can't use WebSockets over HTTPS, but you can use WebSockets over TLS (HTTPS is HTTP over TLS). Just use "wss://" in the URI.
How do you create a WebSocket in Python? ›WebSocket Client with Python
Create a new File “client.py” and import the packages as we did in our server code. Now let's create a Python asynchronous function (also called coroutine). async def test(): We will use the connect function from the WebSockets module to build a WebSocket client connection.
If you need quick help join the Aternos Discord. DW lol every minecraft server logs the IP of players whenever they join. Even every site, browser, ISP all logs your IP so don't worry. If you are using mobile data then its best just turn off ur internet and turn it on again.
What is the most popular Minecraft server? ›#1 Hypixel - hypixel.net
The undisputed king of Minecraft Servers in terms of popularity currently is Hypixel. It's the only server that has ever managed to reach the tremendous milestone of 100,000 online players.
- Find a server on a Minecraft server listing website.
- Read the descriptions and pick one you like. ...
- Start Minecraft, click Multiplayer and click Add Server. ...
- You will be taken back to the server list. ...
- Click the server, click Join Server.
Cross-site WebSocket hijacking (also known as cross-origin WebSocket hijacking) involves a cross-site request forgery (CSRF) vulnerability on a WebSocket handshake.
How do you test WebSockets? ›...
Use ZAP's WebSocket tab.
- Origin. ...
- Authentication. ...
- Authorization. ...
- Input Sanitization.
Unlike HTTP, where you have to constantly request updates, with websockets, updates are sent immediately when they are available. WebSockets keeps a single, persistent connection open while eliminating latency problems that arise with HTTP request/response-based methods.
What is Web socket server? ›
A WebSocket server is nothing more than an application listening on any port of a TCP server that follows a specific protocol. The task of creating a custom server tends to scare people; however, it can be straightforward to implement a simple WebSocket server on your platform of choice.
Is WebSocket a protocol? ›1.7.
The WebSocket protocol is an independent TCP-based protocol. Its only relationship to HTTP is that its handshake is interpreted by HTTP servers as an Upgrade request. By default the WebSocket protocol uses port 80 for regular WebSocket connections and port 443 for WebSocket connections tunneled over TLS [RFC2818].
- #0: Enable CORS. WebSocket doesn't come with CORS inbuilt. ...
- #1: Implement rate limiting. Rate limiting is important. ...
- #2: Restrict payload size. ...
- #3: Create a solid communication protocol. ...
- #4: Authenticate users before WS connection establishes. ...
- #5: Use SSL over websockets. ...
- Questions?