Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Different Result Between Running Application through Simulator and through Executable
Started by PHB Dec 18 2018 04:15 PM

No replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

PHB

[GLOBAL: userInfoPane.html]
PHB
  • Observer

  • 3 posts
  • Corona SDK

I put this in networking because my build uses networking, but I am not sure that is the problem. I will have my code at the end (and yes I know it's messy but all I care is that it works lol).

 

Basically, the clients put in the IP of the server and the server sets a tempo for a metronome and plays. It works fine when I first build it (open in Corona simulator, press build at the top, choose Windows, then choose "Run the App" when it pops up), but when I choose "View in Explorer" and run it, or just run it regularly, it does not work. I've tried running as Administrator and it still doesn't work. Because I'm running it from the executable, no console shows up. Thanks.

 

Client:

-----------------------------------------------------------------------------------------
--
-- main.lua
--
-----------------------------------------------------------------------------------------

--PreReqs
local socket = require("socket")

local getIP = function()
	local s = socket.udp()  --creates a UDP object
	s:setpeername( "74.125.115.104", 80 )  --Google website
	local ip, sock = s:getsockname()
	local ipSockTable = {ip, sock}
	return ipSockTable
end


--Vars
local font = native.newFont("Helvetica-Bold", 100)
local ipTextVar = ""
local baseTime = 0
local actualTimeElapsed = 0
local curTime = 99999999
local standardSystemTime
local isOn = false
local isCon = false
local alreadyPlayed = false
local audioFile = audio.loadSound("TickSound.mp3")
local udpVar = socket.udp()
udpVar:settimeout(1/30)


--Create
local connectButton = display.newRect(160, 320, 250, 70)
local connectText = display.newText("Connect", 160, 320, 250, 70, font, 30, "center")
local clientBox = native.newTextField(160, 200, 250, 70)
local ipDisplay = display.newText("Your IP: "..tostring(getIP()[1])..":"..tostring(getIP()[2]), 160, 470, 250, 70, font, 20, "center")


--Setup
connectButton.fill = {0, 1, 0}
connectText:setFillColor(0, 0, 0)


--Functions
local function editIpText(event)
	if event.phase == "ended" or event.phase == "submitted" or event.phase == "editing" then
		ipTextVar = event.target.text
		print(ipTextVar)
	end
end
local function connectTap()
	udpVar:setpeername(ipTextVar, 46362)
	print(udpVar)
	udpVar:send("drumline")
	isCon = true
end
local function compareTimes()
	--print("frame")
	if isOn == true then
		print((system.getTimer() / 1000) - standardSystemTime + 1.5)
		if (system.getTimer() / 1000) - standardSystemTime + 1.5 >= curTime then
			if alreadyPlayed == false then
				audio.play(audioFile)
				alreadyPlayed = true
				--connectText.text = "Play"
			end
		end
	end
	if isCon == true then
		data = udpVar:receive()
		--print(data)
		if data == nil then
			--isOn = false
		else
			print(data)
			local testStart, testEnd = string.find(data, "b")
			local stopStart, stopEnd = string.find(data, "s")
			if testStart ~= nil then
				isOn = true
				baseTime = string.gsub(data, "b", "")
				local curTime = os.time()
				repeat
				until os.time() == curTime + 1
				actualTimeElapsed = os.time() - baseTime
				standardSystemTime = system.getTimer() / 1000
			elseif stopStart ~= nil then
				isOn = false
			else
				alreadyPlayed = false
				curTime = tonumber(data)
			end
		end
	end	
end


--Events
clientBox:addEventListener("userInput", editIpText)
connectButton:addEventListener("tap", connectTap)
Runtime:addEventListener("enterFrame", compareTimes)

Server:

-----------------------------------------------------------------------------------------
--
-- main.lua
--
-----------------------------------------------------------------------------------------


--PreReqs
local socket = require("socket")

local getIP = function()
	local s = socket.udp()
	s:setpeername( "74.125.115.104", 80 )
	local ip, sock = s:getsockname()
	local ipSockTable = {ip, sock}
	return ipSockTable
end


--Vars
local font = native.newFont("Helvetica-Bold", 100)
local tempTextVar = ""
local baseTime = 0
local nextElapsedTime = 0
local isOn = false
local howMany = 0
local ipTable = {}
local portTable = {}
local udpVar = socket.udp()
udpVar:settimeout(1/30)
udpVar:setsockname("*", 46362)


--Create
local startButton = display.newRect(85, 40, 100, 70)
local startText = display.newText("Start", 85, 40, 100, 70, font, 30, "center")
local stopButton = display.newRect(235, 40, 100, 70)
local stopText = display.newText("Stop", 235, 40, 100, 70, font, 30, "center")
local tempoLabel = display.newText("Tempo", 160, 150, 250, 70, font, 30, "center")
local tempoBox = native.newTextField(160, 190, 250, 70)
local ipDisplay = display.newText("Your IP: "..tostring(getIP()[1])..":"..tostring(getIP()[2]), 160, 470, 250, 70, font, 20, "center")


--Setup
startButton.fill = {0, 1, 0}
stopButton.fill = {1, 0, 0}
startText:setFillColor(0, 0, 0)
stopText:setFillColor(0, 0, 0)


--Functions
local function sendAll(data)
	--print(#ipTable)
	if #ipTable > 0 then
		for i = 1, #ipTable do
			udpVar:sendto(data, ipTable[i], portTable[i])
			--print(ipTable[i]..portTable[i])
			--print(data)
		end
	end
end
local function addTo()
	howMany = howMany + 1
	nextElapsedTime = howMany * (1/(tostring(tempTextVar) / 60))
	print(tempTextVar.." "..nextElapsedTime.." "..howMany)
	if isOn == true then
		sendAll(nextElapsedTime)
		timer.performWithDelay((1/(tostring(tempTextVar) / 60)) * 1000, addTo)
	end
end
local function stopTap()
	isOn = false
	sendAll("s")
end
local function editTempText(event)
	if event.phase == "ended" or event.phase == "submitted" or event.phase == "editing" or event.phase == "began" then
		stopTap()
		tempTextVar = event.target.text
		print(tempTextVar)
	end
end
local function startTap()
	isOn = true
	local curTime = os.time()
	repeat
	until os.time() == curTime + 1
	baseTime = os.time()
	sendAll("b"..baseTime)
	nextElapsedTime = 1/(tostring(tempTextVar) / 60)
	howMany = 1
	timer.performWithDelay((1/(tostring(tempTextVar) / 60)) * 1000, addTo)
end
local function addClients()
    local data, ip, port = udpVar:receivefrom()
	--print(data)
	if data == "drumline" then
		table.insert(ipTable, ip)
		table.insert(portTable, port)
	end
end


--Events
tempoBox:addEventListener("userInput", editTempText)
startButton:addEventListener("tap", startTap)
stopButton:addEventListener("tap", stopTap)
Runtime:addEventListener("enterFrame", addClients)



[topic_controls]
[/topic_controls]