Hi, Sorry if this is the wrong place to post this but I’m currently trying to implement a multiplayer feature into my game however I haven’t gotten very far. My game runs on iOS, Android and soon to be Apple TV so I need somthing that will work on all of those platforms. Making a simple socket server seems to be the way to go but I have no idea what I’m doing and after a week of trying to find info I’m still clueless. Could anyone send me a simple socket server where the server can talk to the client and vice versa or point me in the right direction? I’d like somthing where I can just call a function and tell the function to send a string to the other device so that I can send current scores or if a player is dead or alive between devices. Thanks
I’d google for:
- Lua Socket
- Lua TCP
- Lua game server
- Lua server
- … you get the idea.
I’d also search over at github.com
Lastly, I have a modified copy of AutoLan, but I can’t tell you how well this will work for you as I haven’t used it for a while and things in the land of security have changed for Android, iOS, and Apple TV:
https://github.com/roaminggamer/AutoLan-IPv6
also found this:
https://forums.coronalabs.com/topic/26339-p2p-udp-tutorial-example/
Thank you, this should help me out a little
I may have something to post back in a few day.
So I’ve spent the best part of today using the information you told me to look up ways to do this. I’ve found many things like app wrap that allow you to use their service to achieve multiplayer however something like this inst what I’m looking for. Id like to have it so that a player can host a game from their device and another can join and it would work by sending strings to and from the devices. I found the original AutoLAN and it seems to be exactly what I’m looking for but it is old and no longer works and the newer IPv6 version is also broken due to being outdated. Making my own simple socket server seems to be the best option for cross-platform local multiplayer. I looked at the link you sent (https://forums.coronalabs.com/topic/26339-p2p-udp-tutorial-example/) and this would work for me however it only sends things from the client to the server and you cant send things from the server to the client and that wouldn’t work for me. Is it possible for you to modify it to send stuff both ways? my attempts at this just make corona freeze up and crash.
Hi. I have a different solution. I’ll try to post it in the next few days. I’m crushed right now.
Tip: When posting in the forums, if you avoid wall-of-text (WOT) posts and make your posts easily accessible/legible you’ll get more and better responses.
I don’t generally read WOTs, but since I was already in this thread I browsed your post briefly to respond.
Looking forward to what you’re going to post … I still have an old prototype on my drive I’d like to turn into a real game in the future and it was using AutoLan (can’t remember the version)
I dug up an old product of mine and stripped out the Client-Server Code.
https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/11/peer2Peer.zip
It is not perfect, but it still seems to work.
This example uses the client/server modules to:
- Create an app w/ two choices.
- A. Be the server
- B. Be the Client.
- After you select server (can only be one) or client (1+ is OK), the app allows you to send and receive messages.
https://www.youtube.com/watch?v=sbYwcc4DmgY&feature=youtu.be
Notes:
- The code in main.lua uses SSK for the buttons and to set up the message event listeners.
- The two modules each have a tiny summary of functions at the top.
- From any client, you can send messages to the server, a specific client, or all clients.
- From the server you can send messages to a single client or all of them.
- While this code seems to be functional, you need to verify it on all targets and between them.
- You need to set up ATS in build.settings if you want to test on iOS. I forgot to add this in the example.
- If you find this fails in some cases, please post back with specific details about the failure and test device(s) so I know it failed.
- I may add this directly to SSK later, but right now you get an early sneakpeek.
- I used ‘localhost’, but you may need to use the machine IP instead. The code to set that is already in the example, just commented out.
PS - I have only tested this on Window 10 running three instances of the simulator (2018.3363).
PPS - The name of the example ‘peer2Peer’ is a misnomer. Originally I tried to provide a pure Peer-to-Peer (serverless) example, but I could not. So, I just used the same base for a client-server solution instead.
Thanks a lot this looks promising, I’ll mess around with it when I have some time today. I’ll let you know how it goes. Also I’ll try to avoid writing wall of text posts, this is only my 2nd fourm post so I’m kinda a noob at writing posts.
I tried running the server in the sim and it works great but as soon as I try it on a actual android device it gives me a runtime error at line 103 in client.lua
Good thing is that it’s exactly what I’m looking for
What steps did you take to debug this?
Did you you update build.settings to enable internet for Android? My sample was only setup for desktop.
Try downloading it again and give it another try. I updated build.settings.
It does not work for me, but I have my WiFi and local network heavily locked down.
Ok will do, if it still persists I’ll see if I can fix it if not I’ll post the error here
I was just wondering how does this work? when it is in the simulator it will connect to another simulator just fine but as soon as I build the app and test a simulator to device scenario it wont receive.
So I went to debug and I see that when the server is created the address is set to “*” and the port is set to 0xc001 but the clients address is localhost and the port is something different as well. Do both addresses and ports have to match? If so how do I do this.
I’m about to do some more debugging which will include running the app on real devices and un-commenting the code you mentioned in your post that uses the machine ip instead of localhost.
But from what I’ve seen so far this is exactly what I was looking for.
Also you where right about the build.settings, I completely forgot to enable the internet permissions that’s why I was getting the runtime error
I’m afraid I don’t have time to give a detailed explaination on how it works. You’ll want to find some external docs on sockets.* and read more about that.
However, to answer some of your questions:
- The addresses do not need to match. However, the devices all need to be on the same sub-net.
For example, if your PC is at 192.168.??.?? then your other devices all need to be at 192.168.???.??? too.
For most folks this is not a problem since they have only one wifi network and it is usually on the same sub-net as their wired network.
- The ports will all be different. Each device that connects will have its own port number.
Hi, I’m working on it now and I’ve tried changing the address of both the server and the client to the ip of the machine that its running on and it works fine in the simulator however it doesn’t work while using the simulator and a actual device.
I’m gonna try it on actual devices to see if its the simulator that’s the problem.
So I’ve tried it on real devices and I’ve messed around with the ports and addresses to no avail. What do you recommend I do to get it to work?