Hello, is there any way to use online multiplayer ...
# korge
m
Hello, is there any way to use online multiplayer in korge? I tried it with AsyncServer, but it didn't work(maybe I did something wrong). How can I implement an online multiplayer?
s
In short: yep, it's very possible. I guess more details are needed to answer specifically your question. Are you going to have a persistent server or will it be a connection between players (to play in one playroom, for example)?
m
Thanks for your help. It should be a connection between the players. It would be nice to have one player who creates a roomcode or an IP and others can join to his room by entering the code.
s
I guess it can be done quite easily when the players are connected to the same LAN (Wi-Fi, for example). Just create websocket server on the creator's device and use websocket clients to connect from other devices. You need to now LAN IP of the creator's device, though. If the players are located in different networks, it will be more challenging. One solution is to use virtual network like Hamachi or ZeroTier
m
Ok. Can you maybe give a quick example what the code would look like in local multiplayer? And maybe tell me how to connect this via Hamachi or ZeroTier? Would be very nice
s
And maybe tell me how to connect this via Hamachi or ZeroTier
I've used them long ago and I just know it will work. It should be easy, just try watching youtube demos and/or google.
Can you maybe give a quick example what the code would look like in local multiplayer?
Websocket is event based messaging system. Usually, you just need to define some actions: what to do when the connection starts (onOpen), what to do when message is received (onMessage), what to do when the connection stops (onClose). Also, you can send a message any time. For messages, you can use Strings or ByteArrays. Again, there are plenty examples about Websockets on the Internet, they should make the idea clearer to you. I see that KorGE has WebSocket implementation but I haven't used this one: https://korlibs.soywiz.com/korio/#websocket-client
m
ok thank you very much
t
I also did a multiplayer game wich ueses websockets to communicate. It can run on desctop and as WebApp but it's a client - server architecture. For now the server is stateless and only transmits all messages to all clients. You can check it out here: https://github.com/TobseF/MagicMaze-Island
m
Thank you, it's a useful example