• Hello, there. I’m creating a custom functionality for a board game in my functions.php
    I enqued a .js file and I’m using some AJAX.

    However, I need my custome page to be real time updated for all the users (5 or 6) viewing it. Websockets seem the way to go, but I can not find any documentation on how to implement them in WordPress.
    Can anyone advice me or address me to a tutorial?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Make your game a plugin instead of just in your theme. Plugins have much more control over loading and they are loaded before themes.
    Plugin Developer Handbook

    Moderator bcworkz

    (@bcworkz)

    Client side websockets are implemented in JavaScript. You’d enqueue the script like any other JavaScript. For the socket server, if it’s time critical, I’d avoid going through WP. Install a separate app to handle websocket traffic.

    Thread Starter ersito

    (@ersito)

    Thanks a lot bcworkz!!

    Any recommendation on what library to use? (as you can guess, I’m an amateur programmer)

    Thanks Joy, too. I’ll look into making it a plugin

    Moderator bcworkz

    (@bcworkz)

    I’ve not used web workers myself. The functionality should be built into modern browsers, no library needed. You just need to verify browser support. if ( window.WebSocket ). Server side code can be almost anything you want. I imagine there are server libraries available, but they will include some inherent overhead. For optimal speed you’d be better off with your own lean and mean custom code. Avoid interpreted languages if you can. Compiled code like C++ will run faster.

    Thread Starter ersito

    (@ersito)

    Thank you!!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Websocket in WordPress’ is closed to new replies.