I want to check if my server is online before launching any activity with an online component.
I have tried using ping
runtime.exec("ping -c 1 google.com");
proc.waitFor();
int exit = proc.exitValue();
but this will always give either exit code 1 or 2, never 0, even when I know the server is online..
I have also tried
Online=InetAddress.getByName("www.google.com").isReachable(10000);
But apparently this function is flakey as hell with external servers, and as such it doesn't work either.
Surely such a basic function as checking if a server is online should be pretty straightforward? does anyone have any ideas I haven't tried yet?
Try connecting to the server, using whatever protocol you are going to use "for real". Just because a server responds to a ping does not mean that the server is running for what you need it for. So, for example, if you are going to make requests of a Web service, perform some simple HTTP operation.
Related
Sorry if this is a silly question, I'm still a beginner in Android and couldn't find an answer to my question. I'm making an Android application that sends an input to a server and executes a Python script on that server to process the given input and generates an output. I was successful in sending data from Android client to Python server using SSH.
I can also use SSH to retrieve the output back to the Android client. However, the Python script takes some time to generate the output, and I can't seem to find a way for the Android client to wait for the Python script to finish generating the output. I was able to do this on internet connection with using Firebase database and have the Python script upload the output into Firebase database and have the Android client listen for changes in database. But I'm looking for a way to do this locally without internet (i.e. Firebase).
So is there a way to make my Android application wait for a message from Python to know it has finished with generating the output so it can retrieve it back using SSH or any other way?
Was a protocol what was send a code what was suppost to say if that 2 files are the same. but i do not remember the name. For u will be more easy to send the storage information's in bits (to the device) and after to start that important transfer. when the device will lost the connection will need to compare the real storage memory with the first information's send it and if has not match to ask the user to reconnect to internet or something like that. Maybe is helping until some one will give u the answer.
Perhaps I am going mad, but I've spent the whole day just trying to get the standard samples on the atomosphere (https://github.com/Atmosphere/atmosphere-samples/) to work. Specifically the 'chat'. The instructions are simple - I follow them:
mvn package
cd samples/chat
mvn jetty:run
I visit localhost:8080 and I see the default page - it tells me it connects to the websockets. I see on the Jetty logs it registers the connection. I enter the 'user name' as requested, and then I get a javascript error 'WebSocket not connected.' - after a couple of minutes it says "Connection lost, trying to reconnect. Trying to reconnect 5000" upon which it then connects and works without any issues. Its the same on Chrome, firefox and Safari. Its also the same on 2 different Macs (mavericks) and 1 Windows 7 PC. It consistently fails like this. I have no firewall, proxy , etc running.
I am going out of my mind, and I cannot proceed with my work/project. Its getting late here and I'm dreading another whole day at this getting no where. Any ideas or can some just test this to make sure I'm not going mad? I posted on the user group but just got 'its your environment'. I've tried 3 environments and it makes no difference.
thanks
Ok. I think this 'Fix' has broken the samples;
https://github.com/Atmosphere/atmosphere-javascript/issues/74
debugging the atmosphere.js I see that webSocketOpened = true; is never set, and hence why the client can't send any messages as it thinks the connection is not open even though it is.
If I used client 2.1.4-SNAPSHOT the samples work fine.
I am trying to achieve a TCP connection between a JavaScript client and a java server. (implementation must be this way I cannot swap to node for the server for example ).
Web sockets implmentation in java looked very complicated. I had a look at Jetty and JWebSocket and was quickly scared off. I have no idea what is going on in the source for them. – So I didn’t have much luck implementing a server using them.
So then I looked for websocket alternatives.
I noticed SocketBridge, It seems very straight forwards and offers exactly what I need for my project so I downloaded that.
I created a simple java server that just prints what I receives and sends a string as bytes back. I used the prebuilt JavaSocketBridge and modified the index.html to point to my server. My server recived the message but nothing showed up on the client.
function run(){
socket_connect('localhost', 31113);
socket_send("Hello from JavaSocketBridge applet");
}
I then decided to build the JavaSocketBridge to see if I could debug the read methods. However my build of JavaSocketBridge refuses to connect with the error.
Java Socket Bridge ERROR: Could not connect to localhost on port 31113
Access denied (“java.net.SocketPermission” “127.0.0.1:31113” “connect,resolve” )
(This was in chrome but it happens in firefox too)
So my questions:
Why does my build get a socket permission error?
Why does the client not receive anything even though the example does from google.com:80?
Notes.
My server appears to be working fine. (I have used a simple java client to test it.
I have used java 1.6 and 1.7 to build the JavaSocketBridge)
I have included C:\Program Files\Java\jre7\lib\plugin.jar
My System is Win7 64 and java SDK / JRE is up to date
Edit. Ive gone back to jetty and got a client/server working, however I will monitor this question.
Objective: I want to make a java program containing a boolean that checks every 5 minutes to see if my games server (cloudnine1999.no-ip.org:port 43594)
Purpose: To restart my game server if it crashes
Problem: Not sure how to check if a server is online using java.
Programs Function: If the boolean returns false(meaning the server is offline) I want the java program to open a specific batch file so the server starts up(in case the server crashes)
I tried finding something on google but I didn't find anything helpful and I'm not quite advanced enough of a coder to figure this out on my own, all I need is someone to instruct me/point me in the right direction of coding a server status checker with java and I can do the rest from there.
I may not be able to respond to your answers until around 4PM Central Us&Canada time zone.
Use Socket to check if the server is up (if it can connect to the IP and Port without throwing an exception). Be careful, some servers don't like these 'empty' connections.
try{
new Socket("cloudnine1999.no-ip.org", 43594).close();
}catch(IOException ex){
// Server probably down, restart it...
}catch(Exception ex){
// Some other problem, likely DNS or security related.
}
Use ProcessBuilder to start it up again.
Shell Script Solution :
I am assuming that server is a Java EE server. Servers are kicked by "bat" on Windows or "shell" script on Linux/Unix. For UNIX/LINUX : The most easiest solution is code a logic, in the SHELL Script that kicks of the server, to LOG the PID of the JVM in a file when the server is started. Then you write a simple shell script to monitor the PID logged by using the command "ps -aef | grep " . If the PID is not there , start the server. You should run this script as the same user who starts the server in its original place. A second solution is to "ps auxww | grep java" . Note the server varaiables which identifies your server. If you run the command , you will know.
Java Solution :
Every server has an admin port which can be monitored using a HTTP URL. Oh,well you can also hit the application url. With a Java Program you can test the connection. If the HTTP Response code is 200 - you are good and if its other than 200 like - 500 / 400 , server may be assumed dead. Then you need to kickoff the server start script.
my question is quite hard to formulate.
Well, is there any server in whole web which one would be able work with testing sockets?
For example to send to server "somehow" and get hmm.. time in the world, or any fancy info.
Please correct english if i make mistake and topic if it makes missunderstood.
You could write your own or use http://code.google.com/p/softenido/wiki/echoserver. I think you can install simple tcp services in windows which will allow you to connect to echo on port 7. Of course you can always use open web servers:
c:\> telnet www.google.com 80
Then type "GET /" and hit enter twice. You should get google's web page.