I have been able to set up my client/server program so the server runs on the PC and the client on the Android. Either an emulator or a device.
The server receives data from the client, but the client doesn't receive data from the server(all UDP). Eventhough the server is getting the client's address from recvfrom.
I want to make it work in both the Android emulator and the Android device(my phone).
I read that the Android emulator has a virtual router. I tried giving the client the ip 10.0.2.2 when running on the same computer as the server, but that didn't solve it.
There is communication between the client and server, it's just one sided.
Anything I am missing?
I am using Berkley sockets on JNI\C++ for Android, and winsock2 for the PC server.
Edit:
I was able to make it work! So UDP can work on Android both ways!
The issue was that select on winsock2 has the first parameter unused, while on linux\Android it is used and called nfds. Sending NULL to that parameter(like I did in winsock2), basically made select always return 0.
Thanks for the help fge.
I was wondering if you would post a link to source code on the udp packet receiving for android topic, there's a lot of questions with no simple answers regarding it. I myself can't find a simple program for udp packet send from pc to android.
Related
I'm making client program for android watch (of android wear OS) using socket connection.
In my server & client program for general computer, I'm trying to change the client part to that for android watch. But, I cannot find a sample code related to socket connection for android watch (of android wear OS).
I learned that android watch usually connect google cloud server through phone, and it is possible to directly connect via WiFi without phone. (https://developer.android.com/training/wearables/data-layer) Those are related to Wearable Data Layer API.
My questions are as follows. I'm not sure that android watch as client directly connects our server (with IP address and port number). If possible, could you give some sample codes for socket connection or URL for the codes? (I googled the related codes but I couldn't find them.)
I hope your many comments and welcome any comment. Thanks in advance.
Depending on the hardware you may or may not be able to connect directly (i.e. without relying on a phone) to your server.
For supported devices you can setup a network connection using the ConnectivityManager as described in this guide on Google's developer website.
Once you have established a network connection you should be able to connect to your server.
What is the easiest way to get information from Andriod to PC via WIFI?
I'm doing an app that receives SMS messages. I want to save the information in a database on a Windows computer, right after the messages have been received.
I've tried:
HttpPost (could not get AsyncTask to work)
JDBC (just does not work)
... and even WebView (could not get findViewById work - seems buggy).
I can start the internal web browser on an external link by code, so it's not a network problem.
If there is a better and easier way please give a simple example.
I hope you have checked the other related questions. You can code a client and server application for your android device and pc. See wireless connection between mobile device and pc for detaield answer.
You can use sockets and listen on a particular port on your PC and then with app you can communicate with it. See how to setup connection between PC and android devices through wifi . These questions would help you to get what you want.
If you have any specific problem with your implementation, you may follow up with code sniplet and your problem. Hope this helps.
Have you tried setting up a TCP server on the device and then sending to the pc with the pc as a client?
i'm working in an android app for comunication with a wireless sensors network, i save the data that i receive from the network in a record file, and now, i want to send that file (normally .txt) to a computer, kinda "server", by WiFi or 3G.
I already know use sockets communication if the "server" is connected to the same WiFi conexion, but the problem appears if i want maybe to send the file to a pc in other place, connected to other LAN. I've been reading about WEBSERVICES but i have some doubts about the communication with web sites, because i don't have one. Maybe, i should create a server online to have some URL where send the record files. (i don't know how to create ir neither :/)
to sum up, i want to send a file from a device (for example with ip 138.100.XX.XX) to another terminal, a pc (for example with ip 192.21.XX.XX)
¿any good tutorial about this? any advice?? what do you think about??
Thank you very much, also for reading :)
Laura
This link may have some help Android device to PC's socket connection.
(This talks about basic connection to other PC before sending data/files)
I want to establish a socket connection between my mobile Android device and my PC, so that a string will be sent from my mobile phone to the Android application running on the PC.
See this tutorial for setting up a TCP connection, which is probably the one you're looking for, based on Java in the PC side which might be the server or the client:
Link
For more basic information about coding a client-server software you can also check this series of YouTube tutorials
I need a client server example and steps to create it on eclipse,
I am using eclipse and i have tomcat7.0 and wamp server in my PC,
I have a device (samsung mobile) that i want to use as server/client and emulator(AVD) as client / server,
How to create a server side app in eclipse? please explain with all steps,
How test / run app?
How are the client and the server going to communicate? Through Wifi/Bluetooth/Using http?The only true client server model that comes in to my mind is having let's say php pages that you are going to send HttpRequests (check this for an example) from your android application and the server will handle. In the case of bluetooth wifi you just have to open a socket and send the data. It must be noted that your pc and the emulator have different ip address range, thus in case of TCP/IP socket it is quite tricky (although I think it is possible) to establish a communication between your android phone and an Android virtual device. I hope I didn't misunderstood anything.