I have an application that was written in Java and runs on the users machine. I now want to build an application on the iPhone which will communicate with my java app.
Can somebody point me in the right direction on how I can send and receive TCP packets with the iPhone, I want to of course be able to do that using wifi and 3G.
Thanks,
You use the NSStream classes. I've found it pretty easy to use.
See the SimpleNetworkStreams for an example.
One problem I found is that the iphone sdk does not include the NSStream method getStreamsToHost:port:inputStream:outputStream: which is what Mac OS examples use to open a NStream connection but there are lots of places that show you how to create your own like here.
Related
I’m not sure if this is the right place to ask this question as this is my first question, but I have the following scenario and I need advice and guidance. Or, if this is the wrong place to ask this question, where should I post it?
I want to create a Java Bluetooth proxy application that will sit in the middle of an Android app and a bluetooth IoT device. I want this Java application to see all the traffic that is being exchanged between the app and the IoT device. I have found similar applications called btproxy and btlejuice, but I want to implement it within Java and I want it to be really simple. I have looked into Bluecove but I'm not having much luck. I’m guessing I will need 2 different machines or VM’s so I can use 2 different bluetooth adapters.
Basically, when you connect the Android app to the computer/VM, the data will be logged and it will be sent to the IoT device. The IoT device will then process it, and send its data back to the Android app via the computer/VM. I’m guessing this relies heavily on the UUID of the app and the device?
Is this possible to achieve, if so, have I got the right topology for this scenario and what would be the best Java API to use and is there any code that will help?
I am working on one android app. I want to connect my local PC to ANDROID device using Wi-Fi(Local).
just like this APP.
I am new to network programming.
Anyone help me to do this some architecture or example or code.
You could use the Server-Client architecture. Depending on what you want to do you could either set up a server in the phone and have a client on the computer that will connect to the phone. Or the other way around, server on the computer and let the phone connect to it.
Here is another thread that have some example code (there is a lot of other examples and tutorials):
Android - Server Socket
There's no way around this except by hard work. You are expected to read the documentation and work through the examples. There are heaps of tutorials on Programming on Android on the 'Net. Use them.
I need an android application to communicate with a java web server using sockets, but can't seem to find any information regarding this. I have only been able to find information about java to java and android to android.
When I first tried doing this, I used the basic knock example taken from Lesson: All About Sockets, most likely written before the android OS existed, and adapted the server side to run on an android. That way I didn't have to make an user interface and could just focus on the communication. The code is here: EchoClient, KnockKnockServer, and KnockKnockClient.
The problems I initially ran into included:
Making sure that both sides knew which port to use.
Making sure I had set the permissions on the Android side to use the internet.
Making sure the client knew the ip of the server.
I posted my version of this code here. It worked one year, and then I had to fiddle with it again when I used it for my class this year. My students got it working, though. You'll get a security flag when you go to the site, since I don't want to pay for an officially registered certificate, but that is a rant for another day :-)
Here is an example how to use sockets in Android. With web server you should do the same. If you want to work with http protocol here is another link.
Idea: create a remote control for your android phone.
Why: I like listening music on my phone in a dock station with speakers connected. Now sometimes I want to turn the volume up/down, change the song, etc. So I need to unlock the phone, locate app that is playing music (Music player, internet radio app, etc.). Sometimes I manage to undock the phone or just mess something up and generally this s*cks.
So I would like to control my phone (on a data connection, not wifi) from the laptop (on wifi).
I had investigated couple of approaches and would like to get some recommendations on them:
Use XMPP. This is nice as there a lots of free XMPP services I can use. Two libraries (both based on smack) that I tried work just fine (Flow aSmack port and Beem smack port). I could automatically create new user on device and present some id/password combination that I (user) would enter on a desktop side to link both devices.
Use JXTA. Should be the next real deal but could be an overkill. I would imagine running a rendezvous&relay server somewhere (need to get hosting to work around firewall/NAT) and creating a peer group protected with password. Use device unique id and password (withing group) to link to the desktop application. (A great eBook explaining p2p and JXTA can be downloaded from here).
Use C2DM. Could be the answer, but notification delivery sometimes can take more then couple of seconds to deliver and there would be no feedback mechanism.
So far first solutions looks like a lot easier choice. Create custom extension or just create chat between both endpoints and use that for relaying commands/messages. But I wonder if I would be abusing XMPP system?
JXTA sounds great, but from all the reading I done it is apparent that it is designed for group communication and service sharing and not a solution for connecting two endpoints.
What do you guys think? I welcome all suggestions too.
UPDATE I do not want to remote to a phone and interactively control it. I want to establish a connection (socket connection) between laptop and phone even if both of them are on different networks secured behind firewalls, routers. With this I could define a protocol to issue commands to the phone (lower volume, mute, start app, etc.).
UPDATE 2 I'm giving JXTA a shot. It is a nice solution but lack of documentation is a bit of a downer. Got VPS FreeBSD server to test RDV/relay side of things. I keep updating this question further as it may be helpful for others.
UPDATE 3 Some more reading:
How to make two android devices to communicate through TCP
Connection between two computers without opening ports using a third computer
UPDATE 4
So far I did not have enough time to further continue my project. I did find an interesting project. At the moment project owners are re-writing their library, you can track their progress here.
why do not you try installing VNC server on machine and then use VNC client on laptop to access mobile
Mobile Shell (Mosh) maybe just the tool you are looking for. I have been looking for a good project to use Mosh, your idea seems pretty interesting :)
I wish to control my computer (and usb devices attached to the computer) at home with any computer that is connected to the internet. The computer at home must have a program installed that receives commands from any other computer that is connected to the internet. I thought it would be best if I do this with a web interface as it would not be necessary to install software on that computer. For obvious reasons it would require log in details.
Extra details: The main part of the project is actually a device that I will develop that connects to the computer's usb port. Sorry if it was a bit vague in my original question. This device will perform simple functions such as turning lights on etc. At first I will just attempt to switch the lights remotely using the internet. Later on I will add commands that can control certain aspects of the computer such as the music player. I think doing a full remote desktop connection to control my device is therefore not quite necessary. Does anybody know of any open source projects that can perform these functions?
So basically the problem is sending encrypted commands from a web interface to my computer at home. What would be the best method to achieve this and what programming languages should I use? I know Java, Python and C quite well, but have very little experience with web applications, such as Javascript and PHP.
I have looked at web chat examples as it is sort of similar concept to what I wish to achieve, except the text can be replaced with commands. Is this a viable solution or are there better alternatives?
Thank you
VNC
SSH
Remote Desktop (Windows)
You can write a WEB APPLICATION. The encryption part is solved by simple HTTPS usage. On the server side (your home computer with USB devices attached to it) you should use Python (since you're quite experienced with it) and a Python Web Framework you want (I.E. Django).
While it is an interesting programming question, perhaps you should ask it on ServerFault instead? There you can probably get a lot of nice input on web-based administration / control tools.
Unless this is a "for fun" project for you, there are about a jillion things out there that already do this. And if you want to control a computer from a web browser, be prepared to require installing some kind of custom plugin - since browsers can't touch arbitrary files on the local filesystem, execute local applications, or do other things that are flagrant security risks.
I've been using VNC for over a decade - free and easy.
http://en.wikipedia.org/wiki/Virtual_Network_Computing
Well, I think that java can work well, in fact you have to deal with system calls to manage usb devices and things like that (and as far as I know, PHP is not the best language to do this). Also shouldn't be so hard to create a basic server/client program, just use good encryption mechanism to not show commands around web.
I you are looking for solution you could use from any computer anywhere in the worls without the need to install any software on client pc, try logmein.com (http://secure.logmein.com).
It is free, reliable, works in any modern browser, you don't have to remmeber IPs and hope they won't change, ...
Or if this is a "for fun project" why not write a php script, open port 80 in your router so you can access you script from outside, possibly dynamically link some domain to your IP (http://www.dyndns.com/). In the script you would just login and then for example type the orders in textfield in some form in your script. Lets just say you want to do some command prompt stuf, so you will basically remotely construst a *.bat file for example. Then the script stores this a fromtheinternets.bat to a folder on your desktop that is being constantly monitored for changes. And when such a change is found you just activate the bat file.
Insecure? Yes (It could be made secureER)
Fun to write? Definitely
PS: I am new here, hope it's not "illegal" to post link to actual services, instead of wiki lists. This is by no means and advertisement, I am just a happy user. :)