If they are going to be on different machines, you will need to use a third party networking service or library to hook them together.
We don’t have an example/documents for this as it’s third party API/libraries but something like a peer 2 peer WebRTC connection could work well for this: WebRTC data channels - Game development | MDN