I want to create an app that can send and receive files like text and images between multiple users in android without any net connections. Just to create a local server in one device and use it as a hotspot for transmission of data.
Any suggestions?
You can do this by using socket programming.
https://docs.oracle.com/javase/tutorial/networking/sockets/
In nut shell, The device which you would like to make as server should create a server socket and continue listening to a port. All client devices can create a client socket and connect to the server socket and transmit data.
You can refer to the sample app "Bluetooth Chat" which is available with Android sdk sample. You can use the same concept to transfer files as chunks of bytes (part by part).
Good luck!!
Start with basics
(https://en.wikipedia.org/wiki/Communications_protocol)
Think about what you want to achieve.
Choose your protocol or technology (HTTP, FTP, REST, UPnP or
thousand-others)
Then move on to implementation. You are likely to use some existing library.
Related
I am trying to figure out a solution for a signaling server for an Android WebRTC based project. Both clients will be Android and both located close to each other, i.e. - within 100 yards or less. I would like the solution to work without the use of a public signaling server. I would rather just have one of the clients also act as the server.
So, my question is :
1. How can I achieve it so that one is the server? i.e. - Can I set one as a hotspot or use wifi direct?
2. If I can achieve #1, then what is a good solution for a signaling server running on android ? Can I run one of the nodejs servers on android ?
A signaling server is simply a way to exchange messages between two parties. In the WebRTC case these messages are the offer/answer and ICE candidates.
You can use whatever type of server you want to do this, you can even do it manually :).
You can use one of the clients as the server too, but then you will have to communicate the IP to the other somehow. Maybe use Wi-Fi direct and get it programatically.
With WebRTC, signaling server is just the way to help you transfer your message, exchange your information (SDP package(createOffer/answer), exchange candidates etc).
Example : You can use GCM (Free) as a signaling server, or using Nodejs with socket.io, websocket, XMPP etc. Only thing you need is transfer your message between two peers.
You can refer to this tutorial : http://www.html5rocks.com/en/tutorials/webrtc/basics/
Most chat applications can run both server and client simultaneously, well in my case all I need is to connect all devices that uses my app to share data( gson object), in official documentation, I found direct WiFi connection (p2p) which doesn't work if the other device is not on local network, and socket ( server client separated ), which work only one way one device for sending and the other for receiving.
So does anyone have an example of connecting two or more devices trough internet by running both server and client socket in the same time.
It's not so simple. The simplest is that each сleint create server. And every minute was looking for other servers on the local network. For example, sending a certain packet to a port.
Look about it here.
Then you will not care how customers relate to each other.
Is there a way to push data from local server (hosted on intranet) to an Android application without internet connection? The app is supposed to work only on LAN over wifi. GCM is out of picture as internet connection is not available. However the app will be running on both the devices all the time.
The model, I am talking about, is something like this:
Devices: Local Server - Wifi Connection - Android Device 1, Android Device 2
Android Device 1 updates some data on local server over wifi... Server needs to notify Android Device 2 about the change over Wifi.
Thank You very much for the help
Yes, it is possible.
I used sockets connection to do so.
requestSocket = new Socket();
SocketAddress socketAddress = new InetSocketAddress(ipAddress, portNumber);
requestSocket.connect(socketAddress, timeOutPeriod);
At the server end, you need to open those sockets and ports using whatever languages you prefer. After which you can read or write data using streams.
You should be looking at something like socketIO for that used in a project not that long ago and as long as you know the server address and it is the same on both devices you should be able to push data to and from the server from any device. A group of us used it to make a note taking app. you may need to build your app in html and javascript unless you want to use the java socket communication that would also do the job but more work would be involved.
May be you can implement Message Queue using message server
I'm trying to develop a proyect like PTTDroid, I mean a Push-To-Talk or Walkie-Talkie application.
The issue is that in this app you can´t use 3G to access the web, so I've decided to use a Node.js server and implement an Android client to comunicate with it. I tried to do a multiplattform proyect using Phonegap the problem is that for audio record you can't access to buffer, you can only start and stop or pause the recording process but not send data while capturing. So my problem is that is possible to streams audio capture in real time by native Android functions (Audiorecord class) with a Node.js server by Socket.IO or similar?
I discovered this project, Asimi JS, but I don't know if someone else knows a better way to do what I want.
Thank you very much for your help!
It is certainly possible to do it, but a standard NodeJS http server would not be advisable as it uses tcp. You want to use UDP as a transport layer for audio, since it will be faster and the small packet loss that can occur will most likely not be a problem.
To be completely honest with you it sounds like you need to write a few demo applications on the native platforms - so do not use phonegap. You need native platforms in order to access things suchs as the mircrophone and to stream over UDP.
When you have a demo working, you can go on and try with another platform afterwards, but start with a simple setup instead of trying to do it all at once - if it was that easy, someone else would have done it before you.
Let me recommend a simple UDP server in whatever language you are most comfortable with such as (NodeJS, Java, C, C++, C#). Let the UDP server receive and save the content into a file that you can then play back on a desktop computer to verify the result. As a simple client, build one either on Android or iOS, and stream a file that you have already recorded and included in the app. When you have this setup working, you can try to capture the microphone, then do a user interface, then support multiple phones, then build a server which records the conversations, then build a user database, and so on a so forth. But start with a prototype of your main feature.
I've finally discovered and solved my problem (at least that's what I think)...First of all I created a server to send and receive UDP packets by DatagramSocket and after that, to achieve communication between server and client, when I was connected by 3G, I needed to have a static port and IP, that's why my server couldn't connect with the client. With data connection, the user IP and port is not always the same and you have to keep the same socket always opened if you want to send and receive. On the other hand the server has to store the adress and port from the client in the moment of connection.
Thank you very much for your help ExxKA
I am writing a flashcard program and would like to see the question on my android phone and at the same time want the answer to pop up on my PC. So the phone needs to push the answer to the PC, which is listening. The entire thing would go through wifi.
My current plan is to build an http server on the PC as a separate java application and use HTTP requests from the phone to push the flashcard answer. Is this a good idea or is there an easier way to do this, without HTTP? I just need to send single strings.
You can use HTTP, just create a TCP Listener on Port 80 and filter header messages out, the android part would be easier, because there are several api functions for http requests.On the other side, a simple TCP Listener on any other Port would be better, because Skype is using for example port 80, and the performance would be a little bit better. The android part isnt much harder, you only have to set up a client on your port, and then send your message to your pc.So i would suggest to use a custom port and a TCP Server on your PC and a TCP listener on android.