Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]

Simple Socket Server For Local Multiplayer Game
Started by hmclark2014 Nov 12 2018 04:22 PM

27 replies to this topic
socket network games

Best Answer roaminggamer , 13 November 2018 - 09:55 AM

I dug up an old product of mine and stripped out the Client-Server Code.




It is not perfect, but it still seems to work.


This example uses the client/server modules to:


1. Create an app w/ two choices. 

  • A. Be the server 
  • B. Be the Client.


2. After you select server (can only be one) or client (1+ is OK), the app allows you to send and receive messages.




  1. The code in main.lua uses SSK for the buttons and to set up the message event listeners.
  2. The two modules each have a tiny summary of functions at the top.
  3. From any client, you can send messages to the server, a specific client, or all clients.
  4. From the server you can send messages to a single client or all of them.
  5. While this code seems to be functional, you need to verify it on all targets and between them.
  6. You need to set up ATS in build.settings if you want to test on iOS.  I forgot to add this in the example.
  7. 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.
  8. I may add this directly to SSK later, but right now you get an early sneakpeek.
  9. 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.

Page 2 of 2 1 2
[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Corona Geek

  • 7,544 posts
  • Corona SDK

Hey man.  Don't hold out on us here.  There are a lot of people (including me) who want to know the final solution.


Just attach the modified UDP*.lua files and main.lua with a sample call/setup (all in a single zip file) to a post below (click 'more reply options').  That should be enough.


I know you promised to give this later, but since it is essentially working now I know it would benefit me and many others to see it sooner rather than later.



  • Michael Flad likes this

[TOPIC: post.html]

Michael Flad

[GLOBAL: userInfoPane.html]
Michael Flad
  • Contributor

  • 225 posts
  • Corona SDK

+1 to roaminggamers request

[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Observer

  • 18 posts
  • Corona SDK

Sorry I’ve been away since I last replied and haven’t been able to work on my game or reply in the fourm. Basically all I did was make the server display it’s IP and then I implemented a prompt in the client that asked for the server IP (kinda like how minecraft works if you’ve ever played that)

Page 2 of 2 1 2

Also tagged with one or more of these keywords: socket, network, games