Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello,
There are ten android devices or more in a room. One of them begins to broadcast his name and IP address to other.
Other devices receive it and send to first device their names and their IP addresses. The first device receives names and IP addresses one by one and sends them a string. This scenario may be loop.
I search a lot and find TCP and UDP protocols for doing it. But UDP is unreliable, speedier, useful for broadcast, and TCP is reliable, slower, useful for unicast.
Now I decide to do first step(broadcast by one of the devices) with UDP, and after detecting IP addresses make TCP communication.
Is that a correct work? Can I do it?
Thanks
Posted
Comments
[no name] 29-Jul-15 23:55pm    
Sure if that is what you want to do, do it. We would have no idea if you are able to do it or not.
suraty 30-Jul-15 0:05am    
I am a beginner. I want to know is it principled? There is no easier way? Are my searches complete?
Richard MacCutchan 30-Jul-15 3:52am    
Yes that is probably the best way. Send a UDP broadcast and listen for TCP responses. Once you have all the responses then you can communicate with each device via TCP. There are many samples of socket code to be found by Google that will help you. Assuming, that is, that you are already experienced at writing Android applications.

1 solution

You are confusing yourself with TCP (or UDP which is a connectionless protocol, similar to TCP) and network topology, ring in your case maybe.

I would, in this case, suggest that you do not write such a thing. Instead, I would recommend that you create a server for TCP clients and let it communicate with the network. Through your local network, from the router. That server would listen to every message from the clients, client would share their data on the server through network. Then you can generate a response for each of the client.

First step is to get familiar with networking in Java[^]. Android uses Java as official programming language, thus a program written in Java would work fair in Android with a few changes as per Android standards.

In Android, these resources about networking can help you getting started for communicating through WiFi and other mediums for data sharing. http://developer.android.com/training/building-connectivity.html[^]
 
Share this answer
 
Comments
suraty 3-Aug-15 3:59am    
Good, But In my project in first step the server is not declared! Server is who will do broadcast and will say his name and IP to other!
Any device in network may be Server. And other that confirm it are clients.
Is it possible in your recommended options?
Afzaal Ahmad Zeeshan 3-Aug-15 7:03am    
Yes, but you need to understand that when a server starts. There are no clients associated to it. Clients connect to the server after server runs.
suraty 3-Aug-15 8:24am    
Yes, Clients connect to the server after a broadcast action from a device that is server in that time. After receiving that broadcast packet by other devices. In any time it is possible that you or other be server for others.
Afzaal Ahmad Zeeshan 3-Aug-15 8:29am    
When connectiom is established, who is server and who is client is established. What you may be needing is a topology not just a connection. Read ring topology for more on this.
suraty 3-Aug-15 9:01am    
What make a device as server is broadcast action. That action will bind others to the server.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900