LuaSocket questions

13»

Comments

  • AnatolyAnatoly Mod
    edited April 2016 Posts: 876

    Ok, I started understanding a bit.. XCode releases the App, right?

  • I think so, but you need an apple dev account, which is $100 a year :/

  • Someone knows how to list all devices that is connected to your network?

  • dave1707dave1707 Mod
    Posts: 7,912

    There are apps that do it, so it should be able to be done with Codea. At this point I'm not sure how, but I wrote some socket code that gets the IP address of other iPads that are running Codea code to respond back. See the link below.

    https://codea.io/talk/discussion/8392/project-transfer-ipad-to-ipad#latest
    
  • dave1707dave1707 Mod
    Posts: 7,912

    @Silvio2400 Here's some code that will send a message to every device on your network and look for a response. I'm not sure what message needs to be sent for some unknown device to respond to it.

    function setup()  
        socket=require("socket")
        theirIp=""    
        getMyIp()
        setMySocket()
        setTheirSocket()
        parameter.action("get their ip",getTheirIp)
    end
    
    function draw()
        background(0)
        receiveTheirMessage()
    end
    
    function setMySocket()    
        server=socket.udp()
        server:setsockname(myIp,5544)
        server:settimeout(0)
    end
    
    function setTheirSocket()
        client=socket.udp()
        client:settimeout(0)
    end
    
    function getMyIp()
       server=socket.udp()
        server:setpeername("1.1.1.1",80)
        myIp,myPort=server:getsockname()
        ip1,ip2=string.match(myIp,"(%d+.%d+.%d+.)(%d+)")
        print("myIp "..myIp)
    end
    
    function getTheirIp()
        client=socket.udp()
        client:settimeout(0)
        -- send a message to everyone on this network except to myself
        for z=1,255 do
            if z~=tonumber(ip2) then
                client:setpeername(ip1..z,5544)
                client:send("sent")
            end
       end
    end
    
    function receiveTheirMessage()
        local data,msg,port=server:receivefrom()
        if data~=nil then
            print(data)
       end
    end
    
  • Thank you

  • @yojimbo2000 That pong game is super slick! I love how you made the word pong bounce around on the game-start screen. Super cool!

    I've been struggling for years with a real-time multiplayer game written directly in Swift and using Game Center for communicating between devices. It uses the sprite kit physics engine, which is basically box2d, same as Codea, I think.

    Anyway, I'm no expert, but I do have a lot of experience, and re: UDP versus TCP, UDP is the only way to go for real-time games. The simple truth is that to make a multiplayer game feel responsive at all, you must directly convey to your user the most recent communication as fast as possible. TCP can never guarantee this, by design.

    You may already know this, but what almost all existing multiplayer games do is anticipate receiving incomplete data because of UDP, and account for it by running a "master" environment on a server, plus independent local environment simulators on each user's instance of the game. Most of the time, because they're using the exact same physics simulation, the local environment can make up for gaps in data communication from the master, and whenever communication from the master contradicts anything in the local environment, the local environment treats that communication as authoritative, and corrects itself to match it.

    Somewhat counter-intuitively, this makes it harder to sync an extremely simple game like pong. In a complex 3-D environment there are lots of ways to pull clever little tricks to hide what you are doing when you correct sync errors--the simplest being that you wait until the player is looking in a different direction before you make an adjustment that would be noticeable. But that kind of film-flammery is impossible in a game with as few elements as Pong! Ironically, the simpler the game, the harder it may be to successfully implement as a multiplayer experience.

    Please do forgive me if this is all stuff you already know.

  • Posts: 2,020

    @UberGoober nope, I know pretty much zip! I'm glad that I never got round to trying TCP, as it sounds from what you're saying that it would be a waste of time. I think multiplayer is one area where the iPad is decidedly not a good dev environment. On a computer it's so much easier to get two instances of a program running at once. Let me know if you get anywhere with the pong code!

Sign In or Register to comment.