Search code examples
javaandroidsocketsclient-servermultiplayer

Android, Client Server Communication


I have a quick question, I'm going to be creating a multiplayer Android application, the network method I am going to be following is Client Server, one user will become a server, while 3 others can connect to it, the host will use their Wi-Fi hotspot while the other 3 connect to that using their WiFi.

Now my knowledge on networking is quite low and I'm not 100% comfortable with it, but I want to learn it for future reference, but my question is this.

How would I go around doing this? Does anyone know any good tutorials for this? as I'm doing CS style what protocol would be best with WiFi? UDP? TCP? I have done some research, but what do you feel would be the best bet? Also the application only really needs to send ints, nothing massive at all.

Canvas


Solution

  • The main difference between UDP and TCP from your perspective is mainly that UDP is not guaranteed to be delivered. If you are going to send massive ammount of traffic (frequent integer updates) you should use UDP for traffic and TCP for communication setup. If the traffic will be low than use TCP.

    For communication see sockets. Simple tutorial at here for starting

    Of course you should utilize a service and threading for communication.