• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

socket connection iOS to Desktop [HELP]

Engaged ,
Feb 21, 2017 Feb 21, 2017

Copy link to clipboard

Copied

Has anyone used this?

I can get it working when both client and server are running on my laptop.  As soon as I put the client on my iPhone it will not connect.

on the server I am using

server.bind(7934);

server.listen();

on the client I am using

socket.connect("127.0.0.1", 7934);

I've tried using 0.0.0.0 and also tried using my public IP address

I have no clue how to get this to work.

TOPICS
Development

Views

653

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 22, 2017 Feb 22, 2017

Copy link to clipboard

Copied

you need to learn about how IP addresses and local network work

"127.0.0.1" is the localhost address, it not gonna work over your local network from one machine to another

"0.0.0.0" is the "any address" , you use it for server address when you want to listen on any available interfaces

so your problem is a local network problem, you need to know which are the ip addresses of your each machien on the local network (eg. LAN)

on a classic ethernet LAN, one machine could have the address "192.168.0.1",
another machine could have "192.168.0.2", etc.

on the server you would have

server.bind( 7934, "192.168.0.1" );
or

server.bind( 7934, "0.0.0.0" );

and then on the client you would have

socket.connect( "192.168.0.1", 7934 );

also check the firewall of the computers, to connect to a port the firewall need to allow it as open

be sure that the 2 machines connect to the same local network
if you have one local network over ethernet, and another over wifi
they may not be able to communicate with each others

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 22, 2017 Feb 22, 2017

Copy link to clipboard

Copied

You are correct... I know nothing about IP addresses

I tried what you suggested... however still doesnt connect.  Server is on my laptop. The Client is an iOS app.  I've used the IP that I find in my wifi settings on my iPhone that matches the start of my router IP.. 192.168.*.*    ..  it still doesn't connect.  I've also tried enabling port forwarding on my router for the port and the local IP address of the iPhone.  Any ideas ?

So my next question... even if I was able to get this to work. How would I make the iOS device automatically get its local IP address to use?  It's not good if I have to include a settings page in the app for the user to manually enter their IP (find it themselves).. not very user friendly.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 22, 2017 Feb 22, 2017

Copy link to clipboard

Copied

Applauz78  wrote

...

So my next question... even if I was able to get this to work. How would I make the iOS device automatically get its local IP address to use?  It's not good if I have to include a settings page in the app for the user to manually enter their IP (find it themselves).. not very user friendly.

OK, so let's approach that differently: what are you trying to do exactly ?

I will go with this: connect 2 clients on a local network without user intervention/interaction

if you try to do that with sockets, yes you will have to let the user enter the IP address of the server,and it can get worse, if the IP address is provided by DHCP, the user will have to re-enter the address each time this one change, etc.


It is possible to automate so the client and the server autodiscover themselves, but this is advanced network programming over sockets, for example with macOS you have the "bonjour" protocol which allow an iPhone to detect and connect to the iTunes software running on a desktop.

But with AIR there is another solution which is much much more practicable:
use RTMFP on a local network

in short, RTMFP when used over the internet need a rendez-vous server, but if you use it over a local network you don't need a server and can connect many clients with each others.

see NetConnection.connet()

Pass the string "rtmfp:" to create a serverless two-way network endpoint for RTMFP IP multicast communication.

for example:
var nc:NetConnection = new NetConnection();
      nc.addEventListener( NetStatusEvent.NET_STATUS, onConnect );

     nc.connect( "rtmfp:" );

from there you need to setup a NetGroup, make both the client(s) and server connect to it

and the RTMFP protocol will take car of the rest as the a netgroup is setup by a string name not an ip address.

once client(s) and server are connected over a NetGroup you can directly send over the wire

with NetGroup.sendToNearest()

for example:

NetGroup.sendToNearest(  data, "my_group_address"  );

so it is a bit more complicated then that, but it is much much less complicated than doing it over sockets yourself,

from that point either you can just use the NetGroup to transfer the server ip address to the client and continue using sockets as before, or even better use the NetGroup to send the data you were sending over sockets before.

the first argument of sendToNearest is an Object, you can pass a ByteArray and serialise/deserialise any type of complex objects, or whatever you want really.

here some tutorials and sources code

How to make P2P apps without a server?

A sample RTMFP project, and the start of a little game, for use on a wireless domain without a central server.

github vandermore/HotPotato

look into  src/com/vandermore/networking/p2p/RTMFPService.as

it got all the basic bits to get you started

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 22, 2017 Feb 22, 2017

Copy link to clipboard

Copied

What I'm trying to do is this.

on the users phone.. they have an app... lets call it APP 1...  This app is already built .. there is a graph that is displayed as the user is manipulating data in the app.

I want to make a second app (APP 2) that is just the graph... this app could be on PC, Mac, or a phone or tablet.. or AppleTV.  All it will show is the graph.

So I just need the 2 to talk to each other so that APP 2 listens for APP 1 and when it finds it.. it pulls the latest data to populate the graph.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 22, 2017 Feb 22, 2017

Copy link to clipboard

Copied

Applauz78  wrote

So I just need the 2 to talk to each other...

that "little" thing is what I described above

as long as you're using AIR and are on a local network it will work, wether it is desktop, mobile apps, etc.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 22, 2017 Feb 22, 2017

Copy link to clipboard

Copied

LATEST

I need to find a simple example of doing this. I've never done this before

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines