0

I'm trying to develop an Android application which have to be able to transfer data/message between two Android mobiles, as a client server connection using their own Wifi, which having no network or routers nearby. I just tried using Tcp program to do this but it fails, its not connecting, I'm getting ConnectException and connection refused.

[Edited] Is it possible to achieve this using Android Portable Hotspot integrated with application? Is there any tutorial regarding this approach?

Any Ideas, how to do this? Thanks.

Vignesh
  • 3,571
  • 6
  • 28
  • 44

1 Answers1

1

You need to get the two devices networked to each other before you can worry about tcp usage of that network connection.

If one device is willing to perform access-point like functionality as part of a portable hotspot, and you select that as a wirelss network on the other, you may achieve a network connection between the two that can be used for custom traffic. Though there are ways the hotspot could be implemented where that would not work. Also of concern, the "client" device will now be sending all of its network traffic through the hotspot device, including not just foreground apps but anything it decides to do in the background.

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
  • Hi Chris, If I enable the Hotspot in a device "server", and connected to this network from other device "client", can I able to start the TCP connection using ServerSocket programming? – Vignesh Aug 25 '11 at 04:30
  • Hi Chris, Thanks for your answer, now I able transfer data. – Vignesh Aug 25 '11 at 07:04
  • @Vignesh How did you do it? Can you give some comments? – TimonWang Jul 05 '12 at 11:24
  • @TimonWang to do this we need one Android device that supports Portable Hotspot (>= 2.2),enable hotspot in first device (it will acts like router) and connect to it from second device, open socket connection from first after that try to connect to that based on first's ip address, once connection established you are good to go. – Vignesh Jul 05 '12 at 12:22
  • @Vignesh First, how can I get the client device's ip address. Second, is possible for UPNP broadcast packet to cross that "router" and reach the client device? – TimonWang Jul 06 '12 at 01:11
  • It would be easier to initiate the connection from the client device rather than the hotspot device - you kind of know what the hotspot's ip is (as it's your gateway). Otherwise you'd have to figure out how to get the dhcp daemon to give up it's client list, or guess that whoever has a /proc/net/arp entry for the hotspot network must be your client. – Chris Stratton Jul 06 '12 at 02:35
  • @TimonWang Once you connected the client with the router (technically Android device) through hotspot, you can get the ip address programmatically on any one side, once you got you can enter it manually on other side to establish connection and don't forget about the port number for connection. Also when I try those things the hotspot ip address is always 192.168.43.1. – Vignesh Jul 06 '12 at 12:20
  • @Vignesh I found the router ip from the client side, but I have no idea about how to get this ip from the hotspot site. – TimonWang Jul 06 '12 at 12:23
  • @TimonWang Basically what I did is, once the connection established through hotspot, I open up socket connection from server side with its ip address and port number, and from client side I'll initialise the socket connection with server ip address via listening port (I just hard coded the port number) – Vignesh Jul 06 '12 at 12:32
  • @TimonWang Check this question [link](http://stackoverflow.com/questions/6567649/socket-program-for-server-using-system-ip-address) which is about socket programming. – Vignesh Jul 06 '12 at 12:37
  • @Vignesh Thanks, My question is how to get the ip – TimonWang Jul 06 '12 at 12:39
  • @TimonWang I have not done that part as I hard coded the ip address itself better checkout this [link](http://chandan-tech.blogspot.in/2010/12/finding-ip-address-of-your-android.html), it may help you. – Vignesh Jul 06 '12 at 13:00
  • @Vignesh Thanks, I found that hotspot has a special name. With this name filter the ip address and the ip address is really always be 192.168.43.1 – TimonWang Jul 06 '12 at 15:42