Beginning of my multiplayer project with sockets.

I have been experimenting with sockets lately with the purpose of a simple multiplayer game. I hope to use the system to make a 3d multiplayer on day but as I have no knowledge of how to work with 3d I am sticking to basic 2d.
This is what I have made so far. It is designed to be two player, all you need to do is fill in two blanks, one with your IP address and the other with the ip of the other player. It has no features other than up/down and left/right movement, but we all have to start some where.

I’m wondering why you require manual entry of the IP address, when JakAttak has created a multiplayer class with good functionality including automatic lookup of IP address, as well as the ability to search for other iPads. Why not use (and help refine) that library?

I can help you with 3D, but I strongly recommend getting it working well in 2D first. If you can keep the socket stuff completely separate, it can be dropped into a 3D scene easily enough.

Partially because I’m still new with sockets and I’m figuring out what works and what doesn’t. I didn’t want to choose the most complex example to study as the first one I take a look at.

It’s your choice, but I don’t see the point of reinventing the wheel on things like identifying local ip port. I would be interested in helping, if
the starting point was JakAttak’s library, trying to understand and explain it (because I don’t like black boxes any more than you seem to), improving it if possible, and building from there. He’s broken the back of many of the problems.

I took the multiplayer setup JakAttak made for a test run and it looks really promising

I would love to have some help with the 3d aspect of it if I get to that point. A year of two ago before I got on the forums i came across wraiths in the mist. I’m glad I know who made it.

The idea I had for dealing with multiplayer in my project is a socket each built to receive a piece of data about the other player. ie a socket to receive the player’s xpos and another for ypos, and I was going to hade a list of actions that the player can perform, each one having a function called when the sent data is equal to something. Host jumps, client receives message that returns a value of 1. (Psudocode warning) if actionmsg = 1 then jumpaction() end.

Here is an updated version of what I posted above. It doesn’t need the button classes anymore. It uses touch to move.

function setup()
    socket = require("socket")
    local myip = ""
    local otherip = ""
    local port1 = 5400
    local port2 = 5401
    server1 = socket.udp()
    server1:setsockname(myip, port1)
    server2 = socket.udp()
    server2:setsockname(myip, port2)
    client1 = socket.udp()
    client1:setpeername(otherip, port1)
    client2 = socket.udp()
    client2:setpeername(otherip, port2)
    parameter.integer("HostPX", -10000, 10000, 10)
    parameter.integer("HostPY", -10000, 10000, 200)
    parameter.integer("ClientPX", -10000, 10000, 50)
    parameter.integer("ClientPY", -10000, 10000, 200)

function sendMessage()
    print("Client sent to server: '" .. msg_to_send .. "' at","%x, %X", os.time()))

function draw()
    background(0, 0, 0, 255)
    sprite("Planet Cute:Character Boy", HostPX, HostPY)
    stroke(255, 255, 255, 255)
    text("Host", HostPX,HostPY + 50)
    client = sprite("Planet Cute:Character Boy", ClientPX, ClientPY)
    stroke(255, 255, 255, 255)
    text("Client", ClientPX, ClientPY + 50)
    local data1, msg_or_ip1, port_or_nil1 = server1:receivefrom()
    local data2, msg_or_ip2, port_or_nil2 = server2:receivefrom()
    if data1 then
        ClientPX = data1
    if data2 then
        ClientPY = data2

function touched(touch)
    if CurrentTouch.x < HostPX then
        HostPX = HostPX - 5
    if CurrentTouch.x > HostPX then
        HostPX = HostPX + 5
    if CurrentTouch.y < HostPY then
        HostPY = HostPY - 5
    if CurrentTouch.y > HostPY then
        HostPY = HostPY + 5

@Ignatz All of those codea tutorials you wrote are priceless. Classes always have confused me and the lessons are really good at explaining stuff.

@Archimedes - thank you. I tend to write about stuff that confuses me, so I think we are (equally confused) fellow travellers :wink: