I am going to implement an android virtual keyboard for controlling PC.
Here is scheme how I want this application to work:
Phone app connects to running client on the pc.
User press button on the phone.
App sends to client signal indicating what button was pressed.
Client handles app signal(virtually press designed button).
I know most of the classes I will use, however I am clueless about PC client handling signals from the phone(step 4). If you could tell me which class/classes should I use for those "virtual presses" it would be great. Thank you.
The app running on the PC will be a server rather than a client, if the phone connects to it.
It will not be easy to send keyboard events from a Java application (though that might be possible), doing a simple server in C or C++ is probably easier (I assume your PC is windows based). Win32 API has a SendInput method to generate a keyboard event (example: http://batchloaf.wordpress.com/2012/04/17/simulating-a-keystroke-in-win32-c-or-c-using-sendinput/).
The communication between the android app and the PC can rely on a simple TCP socket (UDP is also a valid option but if you begin in network programming TCP is probably easier to handle and more widely used). On the C/C++ server, look at the functions socket, bind, listen, accept and then recv. On the android app, Socket and DataOutputStream classes should do the job.
Related
I am coding on raspberry pi in python. I want to control my pi through internet for that I need to send data from my android app to the running python script on my Pi. For example, if I click a button B on my android app the raspberry pi's python script should get the data "12345" as string or integer through Internet. I will compare the received data and take the needed action in python. Similarly, vice versa. If I click a button in python created by tkinter, python should send some data say "67890" as string or integer to my android app via Internet. I will compare that received data my android app and take necessary action. Constant process of sending and receiving data between android app created in java and python script on Pi should continue. I already created python program and android app without this communication part. How will it be possible to do data sending??
You shouldn't start with communication over Internet. For the beginning its okay to use your local WiFi for that (the code stays the same, but you must not set up your RPi as a Server with DynDNS and stuff like that. Which is as well dangerous if you don't know what you're doing).
Then start with the python-part. Your Pi acts as a Server for your application. So have a look at ServerSockets with Python: like this example. Here you define a Port on which your service runs.
Your python-code will now wait on that Port for an incoming Connection.
Now on your Android-device you need to connect to that Socket.
Socket sock = new Socket("IP-ADDRESS_OF_YOUR_RPi", PORT);
Now your Android is connected with your RPi via your local WiFi (assuming that both are in the same network)
Then you can communicate over Input- and Outputstreams between you Android-App and your Python-Server.
But you should definitely do some research about server-client and TCP socket communication. And connecting this application to the Internet is the very last step you should do (because open ports on servers in the internet are a invitation for criminals).
I would like to be able to use a usb SmartCard reader/writer (NFC) using Flex but I cannot find out how to do it.
I know this approach does not seem the most secure, but I know that, for example, you can use with Flex a usb webcam if the users accepts to give that permission to the web application.
To give you a little background info about why I would need this: We have developped a web application which would be deployed in a local network of an enterprise and which server-side part is developped in java and which client side is developped in Flex. I have managed to use the reader/writer from the java part but that obviously is not practical as we can only use the tag reader/writer attached to the physical server. What we need is to be able to give the client the possibility to use the reader/writer connected to his PC.
If needed, I would have total access to the client machines (if I need to give the application any kind of special permissions).
Thanks in advance for any clue you could give me!
You can't do anything in native Air, which would be the runtime that would expose such an API. You can do a native system app (Windows or Mac) and that app leverages two processes that communicate with eachother.
The main process would spawn two processes
Air client
Smart Card Reader writer
So the main app would work as a HUB between the two.
Maybe it's worth to look at a FlashPlayer app that runs in the browser and communicates with a Java Applet via ExternalInterface.
I have a program that is in C++ on a computer. I also have a Android app (Android version > 4.0). Both are communicating via TCP socket. The C++ program is the Server Socket, and the android app is the Client Socket.
Now, this works well if I tell my Android app what is the port and IP of the C++ server. I would like to be able to discover my C++ program from the Android device. After some research, I found that I could broadcast a message on the network from the C++ program that contains the IP and Port of the computer. Then my android program will listen to the broadcasting address until it listens to the server's broadcasting message.
I don't know how to do that in C++... Is is a good idea? If yes how can I do that? If not, what would be the better idea?
Thanks!
Getting client-server stuff working reliably can be quite challenging; there always seems to be one more edge-case that needs to be resolved. Rather than rebuilding the wheel, I recommend just using an existing library where someone else has already worked out all the kinks. I haven't used it yet, but the AllJoyn open-source project looks very promising.
I'm making a multi-client server chat application with Java.
Is there any way to not use multi-threads (1 thread for every client)?
Because my app runs on mobile, so multi-thread will make it too slow?
I guess you are misunderstanding the concept. A chat app intended to run on mobile device normally works like follows:
You will have a chat server, which is not in mobile application, hosted somewhere. This will communicate with client applications on different mobile devices.
In mobile client application, you will connect to chat server and process the data accordingly. This communication is generally done by socket connection.
Here every application acts individually so you do not need multi-thread in mobile application except any other functionality in your app need multi-threading. You can consider each application as different thread connecting on server socket.
For not mobile application some people use awesome Netty client-server (me too). Probably
some ideas of this server helps you to create right architecture :)
I would like to establish a connection between a mobile device and computer so they can interact with each other. I should be able to send and receive data at both the ends, just like a chat client. How do I go about it? I just want to know the steps involved. I was thinking about sending the data from the device to a database server and then accessing it through the PC, and doing the same on the mobile device, too. Is this a good idea? What alternatives are there?
Since you're using android, this is pretty easy. One easy option is to code a client and server application for your android device and pc. Or, you could just send data on the UDP connectionless protocol.
I'm assuming you know how to build apps for an android phone. There is no need of an intermediate node (a database server or the like), if the goal here is as small as just sending data back and forth.
Here's a good example of a UDP server/client implementation.
And here's a good one for TCP server/client.
Hope that helps.