How can I connect two Android device by socket without server

后端 未结 4 940
半阙折子戏
半阙折子戏 2021-02-08 12:14

I am trying to develop an android application that can exchange data on peer to peer connection with other devices without server. So please suggest how can I do this. Thank you

4条回答
  •  死守一世寂寞
    2021-02-08 12:50

    If you're looking for such P2P over a local network, there are two parts to it:

    1. Discovering peers
    2. Communicating with peers

    Among Android APIs, you can either use Network Service Discovery APIs for this or Wifi P2P Service Discovery APIs.

    There's a wrapper library which which uses these internally and has comparatively better documentation - Salut, which can also be used.

    I also created a library for P2P - Near, which uses sockets directly. The problem I was facing with Android APIs was that discovery wasn't happening with certainty every time and the underlying issue was unknown.

    If you're looking for P2P across the internet, socket IO is a prevalent solution. Even Near should be able to facilitate the transfers if you provide the IP addresses and they're not behind NAT firewalls.

提交回复
热议问题