Custom Types

With custom types you can add your very own Net Types without editing the main server code. It's recommended to use 4 digits for custom Net Types to avoid collisions with the main Net Types that are using 3 digits.

Basic example

Go to /custom folder and open the custom-types.js file.

You'll see an empty function there. Let's add some juice with a basic echo function.

const customTypes = (sock, message) => {
    switch (message.type) {
        case 1000:
            sock.send(utils.objToByteArray({ type: 1000, data: { message: message.data.message } }))
            break;
    
        default:
            break;
    }
}

So, if we send this message:

{"type": 1000, "data": {"message": "Hello!"}}

We'll receive:

{"type":1000,"data":{"message":"Hello!"}}

Easy, isn't it?

Last updated