https://kotlinlang.org logo
Title
m

Michael Sigl

01/21/2021, 12:52 PM
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

SerVB

01/21/2021, 2:36 PM
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

Michael Sigl

01/21/2021, 2:55 PM
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

SerVB

01/21/2021, 3:00 PM
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

Michael Sigl

01/21/2021, 3:27 PM
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

SerVB

01/21/2021, 3:36 PM
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

Michael Sigl

01/21/2021, 5:15 PM
ok thank you very much
t

tobsef

01/21/2021, 7:33 PM
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

Michael Sigl

01/22/2021, 12:08 PM
Thank you, it's a useful example