PrismarineJS / bedrock-protocol

Minecraft Bedrock protocol library, with authentication and encryption
https://prismarinejs.github.io/minecraft-data/?v=bedrock_1.17.10&d=protocol
MIT License
286 stars 68 forks source link

Ping timeout #502

Open 656pro opened 1 month ago

656pro commented 1 month ago

Versions

Detailed description of a problem

i am using bedrock multi instance and one of my accounts keeps ping timeing out and it randomly stops

What did you try yet?

Did you try any method from the API? Did you try any example? Any error from those?

Your current code

const bedrock = require('bedrock-protocol');

// Configuration
const serverHost = 'donutSMP.net'; // The Bedrock server you want to connect to
const serverPort = 19132; // The port of the Bedrock server

// Define account configurations
const accounts = [
    {
        username: 'hiqril',
    },
    {
        username: 'raxFR',
    }
];

// Function to create a client for a single account
function createAndConnectClient(account) {
    // Create a client to connect to the Bedrock server
    const client = bedrock.createClient({
        host: serverHost,
        port: serverPort,
        username: account.username,
        offline: false, // Set to true to enable offline mode
    });

    // Handle successful connection
    client.on('connect', () => {
        console.log(`Connected to server as ${account.username}`);
    });

    // Handle the 'spawn' event
    client.on('spawn', () => {
        console.log(`${account.username} has spawned on the server.`);
    });

    // Handle connection errors
    client.on('error', (error) => {
        console.error(`Connection error for ${account.username}:`, error);
    });

    // Handle Reconnect errors
    client.on('end', () => {
        console.log(`${account.username} disconnected from the server. Reconnecting...`);
        createAndConnectClient(account);
    });

    // Add more event listeners here as needed
}

// Connect each account to the server
function connectBothAccounts() {
    for (const account of accounts) {
        createAndConnectClient(account);
    }
}

// Start the connection process for both accounts
connectBothAccounts();

Expected behavior

to both accounts launch and not timeout every few hours

Additional context

when it times out i sometimes have to wait long hours 6+

extremeheat commented 1 month ago

This is because the server is unreachable. You need to make sure you can connect with a vanilla client when you get that error. If it works sometimes, it could be an temporary issue with the server.

656pro commented 1 month ago

This is because the server is unreachable. You need to make sure you can connect with a vanilla client when you get that error. If it works sometimes, it could be an temporary issue with the server.

it works fine in java and bedrock its just that it crashes / timeout

DhyanCanPlay commented 3 weeks ago

bro just use mineflayer cz you have a java server