Java socket not connecting on some computers - java

I've been making a java SE application on another computer for couple of months with Netbeans. The application uses Javas sockets and connects to another application to the another computer (or to the same) through port 4444. The application connects on the first computer perfectly to another application: runned from netbeans, runned from command line and runned from a jar file.
Now I'm continuing the project on another computer. At first I tried to run the same source on this computers Netbeans debugger. Application starts, and it connects to another application, but it stops immediately. No error messages or exceptions. The screen doesn't freeze, but neither won't the applications start to communicate with each other.
I also tried to run the applications jar file from the command line. The same problem appears. It makes connection to another app, but nothing else happens.
Finally started the application from the jar file by doubleclicking it. Now it makes a connection and starts to communicate with another.
Firewall isn't blocking the application or netbeans. I've also tried to run netbeans with firewall down, but still no results. Java has been updated on both computers. For some reasons the application runs perfectly on some computers, and on others, it does this annoying thing.

It's possible that port 4444 is used by another application.
Check this by using the netstat utility.
Your application should be configurable. I.E. port 4444 shouldn't be hard coded.

Grab a stack trace from the running application. It will tell you where the program is "stuck".
You may also benefit from adding logging to your app. This will drop statements to a file or system out/err that you can use to identify its internal state. For example; when you write to a socket:
OutputStream os = socket.getOutputStream();
while (true) {
System.out.println("write loop:enter");
os.write("machine 1".getBytes());
System.out.println("write loop:exit");
}
Good luck.

Related

Stop a minecraft server from an other cmd windows

i want to stop a Minecraft server (java) from an empty cmd window (in the server window, we just can type "stop" to stop the server),
because I want to automatize the start and the stop of the server with os library with :
os.system("the command i search")
I don't want to kill the task , because with this method, the server is not stopped properly, and we lost a lot of data.
As for automation of the start of the server, that's simple. Either put a shortcut to your server file in your Startup folder in Windows or put a shortcut to your run.bat file in the same folder. For shutting it down, that might be a pain. I can tell from using the os.system() method that you're using Python. Stopping the server from a clear command window is something I don't know how to do, but I did find a "life-hack" you can do. This plugin is made to automatically restart your server at a specific time of day. But you should be able to configure it to just shut down, instead of a restart. Even if you made it restart, you could make the PC it's hosted on shut down just after the server restarts. This would cause a crash, granted, but it would also save all progress.

How to check java application status (Running or stopped) running on a windows server

I have a java jar running on windows server 2012 r2. I have created a task to run this jar on every restart of the server. Now, I need to restart the application whenever its stopped because of some reason. So I should find a way to find the status of the application.
A typical way to handle problems of this sort is with a service wrapper application, of which there are many, each with particular features. Popular examples include
Tanuki, YAJSW, and Procrun, among others. These wrappers have built-in facilities to monitor and keep alive the applications they govern.
If you just want to check whether the application is running, then a common approach is to send probes to some TCP port that it exposes. Many applications open a port specifically for this purpose.

How to figure out what port my application is using from inside Eclipse?

I am trying to write a program that will interface with my bank using OFX4J (Java implementation of OFX). Since I am getting an error, I want to see what exactly I am sending them that is generating the error. I downloaded the Eclipse Web Tools zip, installed it, and opened the TCP/IP monitor, but when I run the program it doesn't pick up anything. I assume this is because it isn't listening to the right port.
How do I see what port my application is using?
in Linux / MacOS, you can do it from terminal: netstat -vatp tcp | grep LISTEN. If you want to actually figure out some ports - just put out breakpoint into a constructor of java.net.Socket#Socket(java.lang.String, int) or java.net.ServerSocket#ServerSocket(int, int, java.net.InetAddress) and start up the application again in debug mode.

Run Maven project on web server in the background

Problem
I have got a working Maven project that I would like to deploy on my web server. I have just discovered Maven and Java is not exactly the primary language I write my projects in, so please excuse any mistakes. When I run my project, a continuous HTTP connection is established and it should permanently run on the server (Basically Push Notifications based on made requests).
Further Information
The server is running on Amazon's Linux AMI.
Proposed Solution
I pack the whole Maven project into a .jar file and run it there.
Q1 How do I run the java file on a server (in the background) ?
Monitoring
Q2 How can I monitor which or how many processes are working in the background ? (I would NOT want the java file to run multiple times, thus PREVENTING it from establishing multiple connections)
Termination
Q3 How would I terminate any background processes, if needed (terminate the continuous http connection)?
Connected Questions
Run java jar file on a server as background process
EDIT
Possibly what I was looking for (I'll test it out and report back): https://serverfault.com/questions/152378/run-jar-in-background-on-linux

Server app hosted on VPS hangs up

I'm developing a simple server-client app. Server application is hosted on a VPS. I have a problem with it: it behaves weirdly... When I test it on my PC it works fine, but when I launch it on VPS it (program) hangs up when a client app try to connect (the protocol is TCP). I can't even kill it with "killall -vs TERM java" command, so I need to reboot a whole VPS in order to restart it. Client and server apps are both written on Java. The VPS OS is Ubuntu. Can anyone give me a piece of advice of that matter please?
Actually, the problem was in the System.out.println("some_text") commands. My server didn't want to work without this commands in certain places. Why - I don't know yet. I'll do some researches conducted with that behaviour. But anyway, that's a subject for another question.

Categories

Resources