1

I need a way to send messages between 2 android devices, 1 a phone and 1 a tablet. I'm using Java to create the app. I'm looking at servers but I can't figure out where to start. Thanks for any help :-)

P.s. Both devices would be using the same wifi connection so could I use a port to send messages

Cœur
  • 37,241
  • 25
  • 195
  • 267
user1056798
  • 245
  • 6
  • 20

3 Answers3

0

The answer depends on how far away the devices are. Right next to each other (inches)? NFC. Within about 20 feet? Bluetooth. Within a hundred meters or so? Wifi Direct, which is peer to peer wireless connections. More than that? You're going to need a central server, because no carrier allows incoming TCP or UDP data- they all firewall it off. Of course all of the longer distance answers will also work for shorter distances. But different solutions here also have different security requirements.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
0

Beside the obvious solution from @dilix you could use a library like JGroups which provides automatic discovery of other devices.

ZeissS
  • 11,867
  • 4
  • 35
  • 50
  • is it still possible to discover other device eventhough they're not connected to the network yet? @ZeissS.... – gumuruh Jul 06 '14 at 03:06
  • Since you are on mobile: Bluetooth, NFC - but I don't think that is reliable. What is your usecase @gumurug? – ZeissS Jul 11 '14 at 09:44
  • well, @ZeissS, to be honest, i'm still looking for the answer for about making the android could scream (say something) through wifi signal when the device is not connected yet to any networks. But, seems no API could handle that nowadays. except for a low level coding (unix sense). Here is my usecase.... http://programmers.stackexchange.com/questions/247000/wifi-communication-between-two-device-without-intermediary-device – gumuruh Jul 11 '14 at 10:16
  • How can this work? If they are not directly connected in any way, they cannot communicate .. Plug them into a wifi for peer2peer or to the internet (3g...) for communication via a server. – ZeissS Jul 11 '14 at 10:51
  • yeah, that's the big case. Probably we should dig deeper into radio signal -programming such of those topics could answer that purposes without being connected at first. @ZeissS no, the device need not to be connected to any network at first. they should discover each other earlier. – gumuruh Jul 12 '14 at 03:27
  • I'm also interested with this topic, to communicate with each other but not with a WiFi spot, it sounds like what Nintendo did in their old NintendoDS pocket console, called *Pictochat*, your use case sounds like that. – RRTW Oct 03 '16 at 06:06
  • And, an app called *FireChat*, it's completely match the "send messages between 2 android devices". – RRTW Oct 03 '16 at 06:45
-1

I think you can try sockets to send\receive messages: http://developer.android.com/reference/java/net/ServerSocket.html

http://developer.android.com/reference/java/net/Socket.html

Try to searh "android socket" and you can find some information even on the stackoverflow.

dilix
  • 3,761
  • 3
  • 31
  • 55
  • This won't work unless the two devices are on the same wifi network, and a hole has been punched in the WAN firewall. No mobile carrier allows incoming socket connections. – Gabe Sechan Aug 11 '21 at 03:12