Network android

I am writing a small program to help.
I need to send data from one device to another (phones), but they are on different wifi networks. Conditionally, in different cities.

Can I just save some string [] with the data to the server or even google disk, so that then the second device will loadStrings () from there?

Or use another method?
If you can do this with the .net library, then how does it work?
I tried to figure it out, it didn’t work out.
Can a couple of lines of client and server to understand?
Briefly, please.
Which team receives the data, which gives?
How to understand what your ip is or how it works at all?

I hope for help.
Peace for everyone.

@NoName ===
i have done something like that for a multiplayer game on line; the server is on line with some http adress; it is written using .net library: it receives messages (strings, which sometimes must be evaluated as integers or floats or boolean…) then it sends messages to all clients or to some of them; as for the clients if they are computers you can also use .net library; as for phones i am not sure (now!) that it is possible and in my case i have choosen to use && java.InetAddress inside a class with a thread; this class receives all messages from the server address then parse them and according to the result send messages to all or to some or to 1 clients. Everything works fine though it was a long way because i can get more than 100 or 200 players connected at the same time, some of them playing alone, some of them playing agains another one and so on…

1 Like

Personally I would use a UDP server. You would have to go into the sketch permissions and enable NETWORK and use the UDP library, which can be found here

As long as both devices are connected to the same network and are listening to the same UDP port, they’ll receive the messages. Keep in mind that when you receive the messages they’ll be in byte format. So you’d have to convert them like with this code:

String bytes2string(byte[] bytes){
  String chaine = str(char(bytes[0]));
  for (int i = 1; i < bytes.length; i++) {
    chaine = chaine+str(char(bytes[i]));
  return chaine;

Where you would have to call bytes2string and put in the variable you received in the parentheses

1 Like

But in the post from@NoName i think i have understood that they are not connected inside the same LAN…One is in Vancouver and the other in London or… Are you sure to get what is wanted with UDP and the lib you are linking??? - As for me i am not. at least it depends of what messages are exchanged. In my case (let suppose) there is a player (in Vancouver) who plays doesnot matter (but in could be long as a message…) and at the same time another one who is playing (in Paris) and send at the same time another (long…) message…With UDP i 'm afraid that in this case your messages disappear…

Oh shoot. Must’ve missed that. Yeah then my solution isn’t going to work sadly.

@TechMaster04 ===
Dont be sad! - Your solution is good for a Lan and i must add that mine one (with tcpIp and Java) is not at all simple to code because you have to queue the messages, syncrhonize the answers, put delays for parsing and so on.Kind of headache!

Oh, I’m not sad. Quite frankly I feel kind of stupid for not realizing that the two devices were on different networks :sweat_smile:

Akenaton can you explain in more detail how to create an http server and how to support it?
If I am mistaken, the .net library also supports android.

I will understand how to transfer data to the server and receive it, I think.
The server-client connection process itself is more important to me now.

I understand that this is a complex process and explain it for a long time, but it is very useful and important to me. Please help to understand.

Akenaton I look forward to you very much. :heart::heart::heart:

Second question.
Is there a way to transfer data directly from client to client?
Well … so that one of the users is the server, and the second is the client.

It seems to me a little easier than a main server.

@NoName ===

  • As for the second question: no, you cannot do that except with P2P (peer to peer android) which supposes that the devices are in the same aerea
  • As for the first one: what have you tried till now? - If you are just beginning (or a beginner!) you have to make things very simple: so using processing you code a server using the P5 lib for that and you install it on some computer (not phone!) with an IP: doing that you will learn the basics for a server; after that you create a client which tries to connect to the server, this client is installed on another device with another IP; then you try to send and receive messages from one to another. Methods for that are very simple to use though you ll see quickly that according to the message you have to add a lot of methods for triming, parsing and so on. When you have done that and everything is working fine you have to put your server out of your Lan ( i mean that it can be acceeded from anywhere); for that you have to use port forwarding and (very often) give a static IP to the server. At last you have to create a client for phones and i dont know wether it is possible with P5: anyway try all the other things and when you are at this point i ll help you if needed.
1 Like

Thank you very much, you gave an approximate understanding of the work of this mechanism.
And it’s pretty hard))

Just in case, I want to clarify. I think you have a lot of experience, you are now the only source of such information for me.
You can’t directly save data to (conditionally) google drive?
Let’s say a document with a player’s progress.
Any option with saving the document is suitable for me, even if it cannot be done every 0.1 second.

@NoName ===

  • As for saving you save inside the server
  • hint for the first point (creating the server) - Not so much hard!

// Declare a server
Server server;
// Used to indicate a new message has arrived
String incomingMessage = "";
//declare a client
Client client;
final String SEP=":";//or another SEParator; useful when there is a complex message

void setup() {
  size(400, 200);
  // Create the Server on port 12345 - or other!
  server = new Server(this, 12345); 

void draw() {

  // The most recent incoming message is displayed in the window.
  text(incomingMessage + "   " width/2, height/2 ); 
  // If a client is available, we will find out
  // If there is no client, it will be"null"

  client = server.available();
  if (client!= null) {
    // The message is read using readString().
    incomingMessage = client.readString(); 
    // The trim() function is used to remove the extra line break that comes in with the message.
    incomingMessage = incomingMessage.trim();
    if (incomingMessage.startsWith("Bonjour du client")) {

      envoieMessage(10, "Coucou du Server");
     println("Bonjour ::::::j'envoie coucou!!!!");


void envoieMessage(int delai, String mes) {
 println("messageenvoieserveur    " +mes);
1 Like

The main problem is that in the near future I am very far from the laptop. And I write through APDE. I don’t understand how to work with all this.

Where to place the server … I think I will find.
But how to compile for an exe file is not clear.

1 Like

@NoName ==== even if “in the near future” you are “far from the laptop” you have to code in order to get a server running!- And the code snippet i have put is the basis for that. How to compile? - As usually: you export your app! - Where to put it: on your laptop in a public folder; then if you want code the client side for a phone, using APDE or USB. As i have told i am not sure that you can use the P5 net lib for that but try and see what happens…

Sorry. And another question, if you may.
Processing = Java.
Is there no tool in Java to connect players with each other?
I saw in games many times like that.

And further. Question number 2.
And if through the Play Market? They also had some kind of algorithm for searching and pairing players.
Have you tried? What do you think?

I do not need 100 people on the server. Up to 4 is enough. Even 2 is enough.

@NoName ===

  • For connecting “players” java tool is to create a server and a client, writing code for server side and client side
  • Of course you can connect two phones and make them exchanging data without a server, but they are on the same lan and can be reached either with P2P or blueTooth, but that is not your case.