Hi,
I want to create a multiplayer game but I cant connect to globalhosts with UDP connection just to localhosts.
Here is my code:
local socket = require("socket") local widget= require ("widget") local client= socket.connect("www.google.com", 80) local ip, port = client:getsockname() udp=socket.udp() udp:settimeout(0) udp:setsockname(IP Address, 41111) local data myip = socket.dns.toip(socket.dns.gethostname()) print(myip) ipp = display.newText("IP = "..ip, 10, 10, native.systemFont, 10) portt = display.newText("PORT = "..port, 10, 20, native.systemFont, 10) sendIP={} sendPORT={} sendIP.text=ip sendPORT.text=port function ButEvent(e) if (e.phase=="began") and (sendIP.text~="") then udpp=socket.udp() udpp:settimeout(0) udpp:setpeername(IP Address 41111) local dg = e.target.id local snd = udpp:send(dg) end end upBut=widget.newButton{ left=100, top=160, width=55, height=25, label="Up", id="up", onEvent=ButEvent, } ball = widget.newButton{ left=100, top=260, width=25, height=25, id="ball", } downBut=widget.newButton{ left=100, top=360, width=55, height=25, label="Down", id="down", onEvent=ButEvent, } leftBut=widget.newButton{ left=10, top=260, width=55, height=25, label="left", id="left", onEvent=ButEvent, } rightBut=widget.newButton{ left=200, top=260, width=55, height=25, label="Right", id="right", onEvent=ButEvent, } local function receiveUdpMsg(e) data = udp:receivefrom() if data ~= nil then print(data) if (data=="up")then ball.y=ball.y-10 print("up") elseif (data=="down") then ball.y=ball.y+10 print("Down") elseif (data=="left") then ball.x=ball.x-10 print("left") elseif (data=="right") then ball.x=ball.x+10 print("Right") end end socket.sleep(0.01) recv= timer.performWithDelay(100, receiveUdpMsg) end recv= timer.performWithDelay(100, receiveUdpMsg)