Problem with Sockets, Asyncstreams

flyingbag

Member
Licensed User
Longtime User
Hello,

I currently have a samsung Galaxy S3 running Android 4.0.4.

I am trying to get my head around sockets and Asyncstreams. To test it out i created and installed the following two apps (server and client) on my device.
Since i have only one android device - i know no other way to test..
(ATTACHED PLEASE FIND THE CODE)

I am trying something very simple:
SERVER CODE:
When you click the "start server" button
Server initialize, Server starts listening
Once Client Connects, The contents of "EditText1" are sent
to client through AsyncStreams

(the IP in the code is the same one used by my WIFI for connecting device to B4a bridge)

CLIENT CODE:
When you click the button - client connects to the server IP
Gets the data from AsyncStreams
Displays it in the label

Problem:
Once the server starts and the client tried to connect - i keep getting the following error:
libcore.io.errnoException: isConnected failed: ECONNREFUSED (Connection Refused)

Anyone can please help with what is going wrong?

Thank you!
 

Attachments

  • ServerCode.zip
    7.2 KB · Views: 543
  • ClientCode.zip
    6.8 KB · Views: 607

flyingbag

Member
Licensed User
Longtime User
Are you using the same port in both the client and server?

If yes, then try to set the ip address to: 127.0.0.1.
Erel, I tried your suggestion and it works great.
Thank you!

Do you need to always use the same port number between Client and Server?

Also - I am assuming if i install this on two different devices and use the normal server IP - the code should work fine ...right?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You must use the same port. This is how the network driver knows where (which listener) to send the packets to.

Also - I am assuming if i install this on two different devices and use the normal server IP - the code should work fine ...right?
Yes. In some cases routers / firewalls block incoming connections.
 
Upvote 0

flyingbag

Member
Licensed User
Longtime User
Can you try it first? I have no means to test it
(also - if IP is an internal one - i doubt that it would work)
 
Upvote 0
Top