Well what I am trying to do, in the long run, is to change some LAN properties when the an ethernet cable is connected to a computer.
I want to run my Java program each time a LAN network is detected. I found a couple questions as to how to do this in C++, but nothing related to Java, specifically. Would this just involve the way I distribute my final application? As in, I could use Jar2Exe Wizard to package my Java program as a Windows service and then just figure out how to run that at startup. But is there any way to do this within the Java program itself?
Don't know what your specific need is but you could try this. This shows how to run windows commands from inside java so you wont have to create an external batch file.
How to Execute Windows Commands Using Java - Change Network Settings
Also check out this answer which talks about retrieving network name in java. then you can combine both!
How to get the wifi network interface name in java
Related
I am working on a project using a Raspberry Pi and a web cam to detect motion.
I have got it to a stage whereby it takes an image and saves it on my computer. What I am wondering is, is it possible to let FileZilla automatically upload the image to my webserver when a new image is taken? Or is there any other ways that I could achieve this?
Since the post is tagged java, I'm assuming that you're using a Java program already or have the basic knowledge to create a Java program.
On to the answer: yes, you basically have two options.
1. Upload from within the Java program. FTP is probably the easiest since most web servers will have an FTP server running. Here is a tutorial you can use: http://www.codejava.net/java-se/networking/ftp/java-ftp-file-upload-tutorial-and-example
2. Use another utility outside your Java program to upload the file to your webserver. rsync would be the tool of my choice (tutorial here). When on a Linux machine (for example, the Pi) or a Mac, you can run a script that syncs the content of a local folder to a remote folder every x seconds:
while true; do <rsync command hier> sleep 5s; done
Note that that sleep period shouldn't be too short or you'll end up running multiple instances of rsync.
When on a Windows machine, you need to find another way to run a periodic process to trigger the rsync.
I am writing an android SSH Client. I have a terminal object that controls the view and an SSH object to send commands to the server.
My problem is that the terminal displays in color during all sessions but when an ncurses application opens, (tmux for example), the terminal displays in black and white.
I was able to find this: http://invisible-island.net/ncurses/ncurses.faq.html#white_black
I am not really sure what that means. Can anyone guide me on more documentation on this, or if there are any open source Java clients that support this feature. I am not really sure how to fix this.
Ok, so you launched the application without the TERM environmental variable set appropriately, and that meant that during the initialization routines the remote operating system believed it wasn't talking to a terminal that could support colors.
Now that you have it set correctly, your colors work. Congratulations! However, setting it inside the application is going to be quite a trick. This is because it needs to be set before you application launches. Otherwise, when the application launches, the low level libraries you are linking into will query the "environment" to see what kind of terminal it has, which determines what kind of terminal codes will be emitted by your application.
This all happens before you app launches; so, effectively, you can't really do it from your application. However, the real solution is a bit more interesting.
SSH makes very few assumptions about the display capabilities of the remote machine. The best way to "fix" this is to have the SSH client set the terminal type according to the SSH client's capabilities. Check your ssh client configuration to see if you can pass in a "better" terminal type.
In fact, having the host operating system assume the client's capabilities will create issues; however, demanding that every ssh client be configured to hand off it's terminal capabilities properly can be logistically impossible. So, you may want to strike a compromise. On the ssh server machine, try dropping a "wrapper script" to launch the application with a color terminal script. It would read something like
#!/bin/sh
TERM=xterm-256color
export TERM
exec launch-app "$#"
and be saved as launch-app-color or something similar.
I have a java application and two different wireless network connections (wifi) on my desktop.
This is a desktop application, not android.
One method of this applicaiton works well with wifi1, second method works well with wifi2.
So far in order to use different methods I have to change wifi settings on my desktop manually.
Is there any way I could change wifi connection setting from the application programmatically ?
Java is a High-Level, Platform-Independent programming language. Network settings, and how you control them will depend on your Operating System, and to my knowledge there is no simple way to expose this in Java.
'
Luckily, some platform-dependent code mixed with Java can help you achieve the result you're after.
The Java
See the Runtime.exec() method, which allows you access to the Windows Command Line or the Mac/Linux Terminal.
The Windows (Adjust for other OS'es)
Now that we have access to the Command Line, we have to run the proper, platform-specific command. See this tutorial for Windows.
Note that it is not a good idea to modify a user's network settings (or anything else external to your application) without their consent.
Actually I am working on a java based application which has a functionality to turn off my system on a specific time and it's working fine but, the requirement says that if any application is open then it should not be close before turn off my system must have to close all the open application manually.
I am unable to find out the solution.
I have never tried this but it looks like you would have to use: Runtime.getRuntime().exec(). This seems to be a pretty good example of how to do this.
Java JNI
https://github.com/twall/jna/
Get the list of all processes via WinAPI and check for user_name in PEB of a process.
Or this http://msdn.microsoft.com/en-us/library/aa390460(v=vs.85).aspx :)
I want to facilate my client to run java program through UNIX command prompt using some shells. It'll look more effecient if they would be able to give input through some GUI. So it can be tested immedietely. I dont want prefer unix commands fro input.
Can somebody tell me how to run Java swing or applet programs in UNIX?
As Thompson mentioned, looking at Java Web Start could be a good idea.
Otherwise, if what you want is to execute, using a *NIX-like terminal, an application located on a remote host and have it rendered on your local display, then you need to do a few things:
you need a working X server on the local machine
you need to export the DISPLAY to the local machine (you can do this by setting up the DISPLAY environment variable on the remote system)
then you need to start your Java app from the command-line.
Hope this helps.
Here's an example of how to export your display over SSH.
Java programs use the X windows system (just like any other GUI on Unix). Assuming your X windows system is setup correctly, you should just open up a JFrame and do your GUI coding just like Windows.
Using the command prompt to launch a GUI is so last millennium. If you can distribute from a server, look into Java Web Start to provide the end-user with a simple and painless install.
Oh, and of course, follow Starkey's advice to throw a JFrame into the mix.
If you have an X-server installed locally, Putty can tunnel the X11-graphics generated by Linux Java back from the server to your local machine, and view it there.
If the above doesn't make sense to you, your next best bet is either running the Java code locally with Java Web Start (and code it to communicate back to the remote server) or run Servlets inside a Java Web Server running on the remote host.
In other words, GUI over a Putty connection is not something which is easily done.