Socket programming

Hi there,

could someone provide a simple demo how to send data through tcp

I found http://www.coronaremote.com/
where he does send data from one device to another (in that case from iPhone to simulator)
using: local socket = require(“socket”)

He does provide a demo ‘remote.lua’ for the server, but to make it round I would need also
a “client” demo how to connect to that server and transmit data.

for example:
i start the server app on one iphone
connect from another iPhone (client) to the server

  • and when lets say a button is pressed on the client the server app does show “button pressed”

thx
chris
[import]uid: 4795 topic_id: 13725 reply_id: 313725[/import]

I posted a remote debugger for OSX and Corona on github a while back.

https://github.com/ianchia/corona_debug_tools/

It has source for both corona client and a socket server on the desktop. It’s a tad messy because I ripped out a bunch of private stuff so I could share it, but this should get you there. You can send messages from desktop to remote Corona client and the reverse.

Hope this helps,

  • Ian [import]uid: 238 topic_id: 13725 reply_id: 50498[/import]

Hi Ian.

thanks for the link… that looks amazing what you wrote… i guess i need weeks to differentiate whats important and what less for me :slight_smile:
I got now already some kind of connection.

my actual problem is: HOW to geht my LOCAL (internal IP)

TILL now I do itwith:

local myip = socket.dns.toip(socket.dns.gethostname())
–> but this only works on simulator

local client = socket.connect( “www.google.com”, 80 )
local ip, port = client:getsockname()
–> but this only works when I have a Internet Connection

How could i get my local IP just in my Wifi without Internet?

:slight_smile:

thx chris [import]uid: 4795 topic_id: 13725 reply_id: 50502[/import]

Have a look at Eric Wing’s post from a few days ago at the bit where he writes:

>>>
The first parameter is the IP address you want to use. Passing “*” as the IP address to our server will use your machines IP address so you don’t have to look it up. The second parameter is the port you want to use. You will need to pick a port number that is available on your system. (Valid ports range from 1024-65535.) The third parameter is the name and location of the file you want to write output to. The forth parameter you should set to true if you want to see output echoed to stdout, or false if you do not.
<<<

Post at http://blog.anscamobile.com/2011/08/automated-testing-on-mobile-devices-part3/

You should be able to pull down the serverside code from github and see how it uses luasocket.

Hope this helps,

  • Ian [import]uid: 238 topic_id: 13725 reply_id: 50531[/import]

Hi there,
thanks for your answer.

i tested that code…

but when I bind to “*” I always get " 0.0.0.0 " for my own IP !

I was already working before with getsockname …
result is always 0.0.0.0 :frowning:

chris

[import]uid: 4795 topic_id: 13725 reply_id: 50547[/import]

I don’t think you can using LuaSocket - it seems to require resolving to an outside IP before it can understand it’s own local IP.

I tried with a few quick tests.

Connecting to a known external IP and getsockname() resolved the local IP (192.168.1.4) correctly.

Connecting using 127.0.0.1 , and getsockname() resolved the local IP as 127.0.0.1.

Trying to connect without external connectivity outside your local network (192.etc / 10.etc) and you’re just stabbing around in the dark with millions of possible addresses because you won’t know the other octets.

There are a bunch of C-style solutions for resolving local IP addresses like Erica Sadun’s:
https://github.com/erica/uidevice-extension/blame/master/UIDevice-Reachability.m

Maybe log a feature request?..

  • Ian [import]uid: 238 topic_id: 13725 reply_id: 50904[/import]