how to connect two different ssh connections to same ssh server - android

I am developing a system that connects two remote devices. I have used ssh for the whole communication. Scenario is such :
Both devices connect to same ssh server having public ip
Both devices are inside NAT
Connection is initiated by both devices
Problem is that both connections are treated as different sessions and I want to make communication b/w the two devices possible.
I am using JSch
Another problem is that I want to use JSch in android and have no idea how to integrate and use JSch example files(say shell.java) in android
The two devices have already established connections to the server,this implies that the settings has to be at sshd (ssh server) that is maintaining this two authenticated sessions. Does SSH server allows this? If yes then how it could be done? Tell me if their is any another way to perform this i.e connecting two remote devices in different networks to communicate by connecting through one public IP.
I am using OpenSSH server just for relaying purpose but dont know how to relay input from one session to another session back and forth i.e I dont know how to configure SSH server

You would have to build a "server" software on the server that would facilitate the communication between the devices.
You can still use the SSH and run the "server" software (or communicate with it) via the SSH/JSch session.
You will run the software using JSch using the "exec" channel. The software will communicate with other instances of itself using mechanism available on that platform, for example using named pipes.
If you want a really trivial solution, you can just use cat - > file on one side and tail -f file on the other side. Try that in two SSH terminals to get the idea.
You can hardly communicate between the devices directly otherwise.

Related

Which ports are used on Android when listening to socket.io on a server

So let's say I make an Android app and I start the socket.io connection by letting it listen to my API on api.example.com. The API is set up to listen to port 3004.
Does this mean that the Android device itself will open up port 3004 in order to use socket.io?
The reason I am asking is because of a customer that has high security standards, and they want to know which ports are required to be opened in order to use our application.
No it doesn't. I mean Android client will open a port up but unlike server it is not constant. You see unlike server's port, client's port is determined when you connect to a socket server and it may be different every time you connect to one. So it is impossible to say which port however you can use tools like wireshark to monitor and find the port of a specific connection.

Communication between android phone and Raspberry Pi over WiFi without external modem/router?

I want to control Raspberry Pi 3 with an android application via WiFi, without external modem/router/...
This application needs to do the followings:
send commands to RPi
send/receive files to/from RPi
So far, I have setup RPi as a wireless access point, and I'm able to find RPi in my android phone via WiFi and connect to it.
But the question is how can I communicate with it after being connected !?
Firstly, I thought using SSH. I tried some ready apps like JuiceSSH. And it was successful. I was able to SSH into RPi and execute commands.
But then I thought maybe there's no need to SSH. Because the RPi itself is a wireless access point, and my android phone is connected to it.
Now here is my question:
Are there any methods (other than SSH) to send commands to RPi or send/receive files to/from RPi after connecting to it !? If so, how can I implement it?
Any sample codes or examples are really appreciated. Thanks.
I don't see a point of not using SSH merely because RPI act as as Wireless access point. Anyways if it's a basic Shell access you need to the RPI from the phone, SSH or Telnet can be easy to setup.
If you are in capacity to implement your own server inside the RPI by code and do something inside the code, gRPC can come handy, given it's available in many languages.
Ex: gRPC server in the RPI, gRPC client in the android app. Basically gives simple client-server system.
There are many other ways to achieve the same thing, depending on your exact requirements and constraints.
Or you can simply start a webserver inside the RPI and use the browser in the phone to access it. This seems more simple and robust.
http://www.instructables.com/id/Python-Web-Server-for-your-Raspberry-Pi/
http://www.instructables.com/id/Raspberry-Pi-Android-App-communication/

Best way to access computer CMD from android

I'd like to create and Android app which allows me to control some aspects of my computer (volume, open pre-defined URL's..etc).
Would it be feasible to create a Windows client from an Android device? I'd like to access my PC's terminal in order to execute some commands.
If so..could you please point me out the right direction?
One possibitly (maybe not the best one) would be to host a apache webserver with access to the cmd by executing it with PHP. You could predefine commands which you call from specific URL paths like http://192.168.1.1/myHomeControl/muteSpeakers/ for muting the speakers.
You can execute cmd commands in PHP with
exec('ping');
or
system('ping');
Then you just need to call the URL from your android Device and it should work.
There are many ways to control Windows machine from another device. Every type of connection depends on particular type of protocol. And as result each protocol has its own rules, pros and cons and restrictions.
You can connect to the machine by SSH using JSCH. But you also need to install SSH server on your machine.
Or you can develop your own protocol using TCP/UDP as transport.
Try this software -- https://play.google.com/store/apps/details?id=com.sonelli.juicessh
Install the ssh on your machine:
For Mac:
http://www.maclife.com/article/howtos/how_enable_ssh_your_mac
For
Linux:
http://www.cyberciti.biz/faq/how-to-installing-and-using-ssh-client-server-in-linux/
For Windows:
http://comptb.cects.com/install-configure-ssh-on-windows/
Connect to it and do whatever you want to do. Have Fun!
If you want to create an application, than there is two options again: either you create a SSH tunel to the pc and you kinda let the user configure their SSH or create an External APP such the PHP , or VB.net that kinda detects by protocols and different ports the access to the machine.
I use this software to control volume and stuff : http://www.unifiedremote.com/ it is pretty good when it comes to control the laptop and and certain types even using the mobile as a mousepad -- To do this they created a software that needs to be installed on the machine to control doing so lets call this software the CONVERTER / RECEPTOR that converts all request that i do from mobile to the pc. Seems simple but not rlly :)
Regards!

need help to make client-server app in eclipse

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.

Client-Server app for Android/Java using dynamic IP

So i want to create an Android application that would send data (in this case coordinates) from my Android device to a Java application on my MacBook via Wi-Fi.
I figured i would use TCP Sockets for the job, and my Android device would act as client while my MacBook as server.
My problem is that in reality hardcoding IP addresses is not the ideal techique for that, is there any way around this? Is using Sockets the best way to make an application like that?
Not getting into the best way to do it, but instead of static ips use a Dynamic Dns Service.
You could use dynamic DNS. With dynamic DNS, client (Macbook) registers its IP address with DNS server, which than serves it to other clients (Android) via normal DNS requests.
However, I'd recommend against this setup (server on notebook with DynDNS):
Your notebook might not be always available, due to personal reasons or network connectivity reasons.
Network address translation (NAT): most client networks (wlan, home networks, even mobile networks) use this technology which prevents initiating TCP connections from internet to internal network (inbound connections). This can be alleviated via port forwarding, but this can only be done on networks that you control.
Instead I'd suggest that you use a virtual private server (Linode) or a cloud solution.
Alternatively, if you don't want to setup/manage a server, than you could use an existing data exchange solution: email, twitter, xmpp, etc..

Categories

Resources