Have you checked your firewall? It may not be allowing incoming connections to your application.
I’ve developed my own server for a specialized application - talking to the Arduino microcontroller and other physical computing devices. It’s here:
http://newecologyofthings.wik.is/NETLab_Toolkit
One thing I’ve noticed is that there is often a NULL character at the end of a transmission, and you have to deal with that in your code. I’ve been working on this for the afternoon, and now have the following code, which checks for a transmission terminated by the NULL. The number I’m interested in is the second element delimited by a space, which is then displayed on the iPhone.
require "socket"
local mainDisplay = display.newGroup()
local textObject = display.newText( "", 27, 29, "Arial-BoldMT", 40)
textObject:setTextColor( 255, 255, 255 )
mainDisplay:insert( textObject, true )
textObject.x = 100; textObject.y = 100;
local getdata = function(event)
data = ""
for i=1,1000,1 do
s, status, partial = client:receive(1)
if string.byte(s) == 0 then
--print("NULL")
break
else
data = data .. s
--print(s,string.byte(s))
end
if status == "closed" then break end
end
dataValues = split(data," ")
--print(dataValues[2])
textObject.text = dataValues[2]
end
function split(str, pat)
local t = {} -- NOTE: use {n = 0} in Lua-5.0
local fpat = "(.-)" .. pat
local last\_end = 1
local s, e, cap = str:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(t,cap)
end
last\_end = e+1
s, e, cap = str:find(fpat, last\_end)
end
if last\_end \<= #str then
cap = str:sub(last\_end)
table.insert(t, cap)
end
return t
end
client = socket.connect("10.0.1.21",51000)
client:send("/service/osc/polling-reader/nlhubconfig/connect 192.168.0.200:10000\n")
client:send("/service/osc/polling-reader/nlhubconfig/listen /analogin/0/value\n")
client:send("/service/osc/polling-reader/nlhubconfig/samplerate 30\n")
timer.performWithDelay( 30, getdata, 0 )
[import]uid: 4366 topic_id: 928 reply_id: 2331[/import]