There is a program called PC^2 (a programming contest judging system). You can submit java files to it, and it will compile/run it.
I have a program that creates a socket, when I submit this to PC^2 it runs it fine, but I can't access the url (http://ip:port/) on my web browser. But when I quit PC^2 (my program is still running) it works when I hit refresh on my web browser. This means that PC^2 is somehow blocking the port, but not occupying it (i.e. making it's own ServerSocket that occupies the port) because if it was occupying it, then my program would have thrown an exception and quit.
What are possible ways that a Java program can do this? And since PC^2 is closed source, I can't look there.
Only one program at a time could listen to a certain port.
Same happens if you start tomcat twice using the some port
This has nothing to do with java. That is how sockets work
If PS^2 is running locally, you could check to see if it's listening before you run your program. I saw PS2 Version 9 uses sockets for communication, so perhaps that's what's going on? In Windows, these instructions will help confirm which process is listening on the ports. In linux, this page will help.
Related
I followed some tutorials (i.e this one)on Java RMI in Eclipse and got the program running.
The trouble is, I can't find any instructions on how to stop the RMI program from running. I want to know for general knowledge purposes, but also because when I try running the program again (after making changes) I get a message that the port is already bound to the previous run which is still active.
The button on the right can be used to toggle between active output consoles. When you reach the console for the RMI server you want to end, click the red square (on the left)
I want to develop a program for ubuntu platform, That listens to DialUp modem and get Calls and send them to my php program that's running on my localhost.
for example when somebody calls my phone line, my listener program give the number and run this query:
http://127.0.0.1:80/listen.php?caller=ThePhoneNumber
How can I do that? is there any classes in java for that?
I think you'd need native tools for that. You can make pppd answer the call and run a custom script or program. But I have not fiddled with that for a long time. See linux modem howto. There should be plenty of information.
I have an applet packaged with a third part dll (from JTwain). My applet scans documents from the TWAIN compatible default printer. The applet fails on a paper jam and won't recover. The user navigates away from the page and the applet is destroyed. When returning to the page it fails again. Closing the browser (which kills java.exe process on the pc), and then returning to the page clears the problem and everything works.
I want to restart everything without requiring users to close down the browser. I've added a GUID query string to the URL's from which the applets resources are loaded - so I know nothing is being cached. I've checked in the windows task manager and there is no process created by the dll, it's all happening within the main java.exe process. I tried wrapping the scanning process in a thread so I could interrupt it in the stop or destroy methods (just in case the applets thread weren't stopped when the applet was destroyed), but that didn't work.
Any suggest would be greatly appreciated. Ideally I'd like some way to restart java when the applet unloads (but I doubt that's possible).
UPDATE
I've spent a couple of days trying to identify what causes the applet to fail. I still don't know :(
When the paper jam occurs something (not my code), is producing a couple of popups. The first alerts the user of the jam, and can be closed by clicking the OK button. The second says 'reading from device' and hangs. It cannot be close with the red, close window, icon in the top corner - I kill it from the task manager and windows asks to send a report regarding the 'non-responsive program'. I assume these popups are produced by the dll. And given that the second hangs, my assumption is that a thread started by the dll has hung while retaining a lock on some component of the TWAIN application. I get
com.asprise.util.jtwain.JTwainException: Failed to open the specified data source:
Source: TW-Brother MFC-9970CDW LAN Thrown
..when I try to access the scanner.
I'm at a bit of a loss as to how I can get more information. I'm testing my applet on a windows virtual pc (so as to use ie7), and don't have a method for step debugging in this environment. (And it's crashing on third party code for which I have no source anyway)
I see only two practical options here:
Use an API that handles paper jam without problems. Of course, that is easy to say (get robust API), harder to find.
Launch the app. free floating using Java Web Start. If it freezes up, the user can kill it and click the link for another instance in a new JVM. Or the applet might also call BasicService.showDocument(URLof.jnlp) if it can detect a problem with the DLL and is not itself frozen.
Of course, you should also report the bug to the ..Asprise(?) developers. The optimal solution would be to have the problem fixed at its source. Anything we do here is a 'workaround'.
I have made a fairly simple turn-based multiplayer web game in an applet. My question is about the performance. I was noticing that there was a really long gap between a player taking his turn and the rest of the players seeing all the updates. It could be as long as 10 seconds for a single move/action.
The game runs on a dedicated server and all the players connect to the server as clients. As one player takes his turn, each move/action is sent to the server, and then from the server out to all the other clients. The server usually sends updates in the form of complete game-state objects, but also sends String messages. The client has a separate thread for listening for these updates. This is all done through a socket connection and persistent object input/output streams.
In my attempt to track down where the bottleneck is, I realized that if I run the applet from Eclipse (clicking "run as applet"), there is virtually no delay. So that means the client applets are sending out updates and the server is receiving them and then sending out it's updates perfectly. The bottleneck has to be in the applet's receiving/processing those updates.
I had two Chrome-applets and two Eclipse applets open on the same game. I would make a move on any of them and the two Eclipse applets would receive the server update instantly and the Chrome-applets would take as much as 10 seconds to get a single update.
Is there something import about different about how the applet runs in the browser vs in Eclipse? I know Eclipse is running the applet from local files, but doesn't a web-applet download all the appropriate files when it starts up? Thanks for your help. Let me know if posting some of my code would help.
I want to install a monitoring system on a computer (the program is a jar file) and run it on start up every time any user logs on. However, I don't want the user to be able to terminate it since then it won't be able to be monitored any longer.
We have tried several ways:
Installing it as a service - the problem here is that our program doesn't work any longer; it can't connect to the computer that's monitoring it. We used "Yet Another Java Service Wrapper" for this, and looked into some other wrappers as well that could help us install it as a service.
Running the program on start up (using the folder startup), but not giving the basic user the privileges to edit/delete/mess around with the files. However, this seems to slow the whole computer down? This doesn't happen when we run the bat file executing the jar directly. Another issue with this is that the user can just go to the task manager and kill the java process.
We tried a variation of the previous one to solve the issue of the process being killed, by having another process. One will spawn the other and these 2 processes will keep tabs on each other. If one terminates, the other detects it and runs it to start it up again. Although it can have issues if the user is fast enough in killing both processes before either is respawned again, the bigger issue is that it sometimes has problems with connecting to other computers. We didn't have this problem when it was just 1 jar.
Does anyone have any idea on how these problems can be solved?
The context here is windows, but if you have suggestions for linux and mac that would be nice too!
Way to go is to run the program as a service. You should investigate any trouble between your application and your system's firewall. If you have windows firewall activated, you should add an exception for java.exe or javaw.exe.
In order to give elevated privileges to your program, you can set the service to run as another user. You can do this from the "Log on" tab in the service properties.
You'll want to have the program started under a user with elevated permissions. On WIndows this would the the Administrator, linux would use root. On Windows, its likely that you will need to start it as a service. But I really don't know why that would hinder the network communications.