Checking if a port is currently in use (Java) - java

So, I've built a server manager in java to boot and close game servers on the extra box that I have lying around, but now I'm looking for a way to close down servers that aren't in use automatically.
My current thought was to check if a port was receiving any data with the server manager, and if it goes for a period without any data being caught, to close the server. That's where I run into the issue of being unable to read ports because java can't bind to a port that is already in use. Is there some way to monitor activity on a port without specifically binding to it?
Any help you could provide would be greatly appreciated!
Thanks in advance!
-Mot
[EDIT]
OS:
Windows 7 Home Premium
What I've tried thus far:
-ServerSockets to bind to the port and listen
-DatagramSockets to bind to the port and listen
I'm currently looking into netstat via cmd to see if I can pull any valuable details from there, but no dice thus far

Related

Can i host my ServerSocket or Java file somewhere on the web?

Heyy guys. I'm writing a chat application in java, works pretty well. But can i somehow host my Server file or the Serversocket on the web? I want to make it so my friends from other pcs can use the client and connect to the server file which is hosted on the web. Is that possible? Can i host the File/socket online?
When you run a java application that opens a ServerSocket, it opens a port on your local machine and starts listening for incoming connections. What you do with those connections is up to the implementation of the java code that you write.
The "web" is much less foreign than you are making it out to be. Your own computer can be on the web that you're talking about and people can connect to your chat service. Or you can choose to host it on something like an AWS server.
The following approach is assuming you are behind a pretty standard NAT config.
Once you run your java application, you need to make sure other computers can see you, either inside your LAN or outside on the internet. You want to start testing from as close to your computer as possible, then start expanding outward.
First you need to make sure that your computer's firewall is actually allowing connections on the port that your java application is listening on.
Opening ports in the Windows Firewall
Setting up and opening ports in Linux
Now computers on your LAN will be able to connect to your java program. Now you need to go one layer out, and port forward your router. This is much less standard so I can't help you too much, but Google can.
At this point, anyone on this internet, knowing your external ip and what port your java application is listening, can connect to your service.
If you chose to host this on an third party hosting service, you'll need to go through similar steps, but there may be slight differences that you can either ask about, or again Google is a great resource.

Need to call from jxfs client to jxfs server

I am very new to jxfs things. I have a requirement to call jxfs server which is in cloud server from the jxfs client which is in ATM environment.. How can i call?.. I need to call this one through the Jxfs RMI concept. It would be appreciated one if any example code is available. If atleast you are having code for calling from jxfs server to jxfs client, please post it.
Thanks in advance guys.
One of the interesting things about J/XFS and remote device access (based on RMI) is that it is just matter of configuration.
You need to configure a J/XFS repository in order to handle a remote device (basically set 'remoteAccess' to true).
Then accessing these devices from the programming point of view is just the same as they were local devices.
Architecture is explained here: ftp://ftp.cencenelec.eu/CWA/CEN/WS-J-XFS/cwa14923/cwa14923-01-2004-May.pdf
Details, when programming may differ depending on the J/XFS implementation you are using.
Trying to answer your question below:
Whenever you want to access a device remotely in J/XFS, RMI is used. You need to make the following setup:
On a server (should be accessible) you need to start a JxfsServer. The JxfsServer will use a Read.repository
whith all the ATM's and devices configured on them as workstations, with the right IP addresses.
On the ATM, you need to install:
J/XFS libs
J/XFS device services for the devices on the ATM
Setup the DSstarter:
Will use the SpecificDeviceManagerRMI connecting to the JxfsServer you started before.
On your server (cloud) wherever you are going to use the J/XFS client you can get the remote controls by performing
the J/XFS initialization as follows:
jxfsDM_ = JxfsDeviceManager.getReference();
jxfsDM_.initialize("com.jxfs.forum.communication.rmi.SpecificDeviceManagerRMI,<atmWorkstation>,AppTest,2006;<jxfsserverhostname>,");
Then you can get the remote device controls with getDevice(...), and start using them as if they were local devices.
Please, note that handling RMI ports can be tricky, specially in a secured environment as ATM network. Make sure all the ports you need are open.

Java router port setup programmatically

I'm wondering if there is a way to setup connection between a client and a server over the internet and have both of them programmatic setup all needed router/firewall configuration changes to open needed external ports to communicate.
Assuming both server and client have known ip addresses and a DNS is not needed in this example to find the IP addresses. How might one have a server that when started configures access past the firewall and tells the router how to route proper communication to the server. I would assume the client may not need anything like this as it should only need to know the external IP address and port number of the server. If i'm wrong about my assumption please let me know.
Example if I have two houses house (A) has a server and house (B) has a client and both sites know what the other house external IP address is and know what port they will be using how may a Java application do all the configuration or at least do as much as possible on say windows,mac,ubuntu. The idea is the user of the server and client should not have to do a bunch of firewall/router configurations to get the application running. It would also be nice if in the example it shows how to release the connections when the server is terminated. Example when the java server is turned off it should close up port settings on the firewall and router. security and clean house.
There is no easy way of doing that as it will depend on the OS and on the many possible firewall application running on the machine. Plus, if your app crash, you will never set back the original parameters, which can be problematic when talking about security. Instead of trying to set up custom configuration, you should try to use standard communication template/protocol like http. This will gives you a high probability of your app running without additional configuration almost anywhere (since there is almost no point of having an internet connection if you don't allow http port).

Failed port-forward for my diy application in Openshift

I have a java application with a server socket, but i don't know how to connect with another java web application in openshift. Looking in forums i saw i had to do port-forward to see wich ports i had to use in the connection between the web application(client) and the java application(server). But i have this error:
http://postimg.org/image/gjrrs80lp/
I did ssh -N 536(..) too, but it didn't work. I'm full blocked, i've never worked with sockets and ports and i'm blocked.
Thanks for the help guys ;)
You might do better to read up on sockets and ports then. Can you give a specific error that you are getting? If you are trying to use a non-supported port, then it will be blocked. If you want to do port forwarding between gears then you need to make sure you have a public/private key setup on your gears for that purpose and added to your account.

server registers ip of my modem continously to use it in my android application

Initially, ip-addresses from the ISP are always changing. I am working on an android app and I need to connect from outside my home to my internal network. I need a server connected to my modem/router and the server should save the public ip of my home network every time it changes.
Goal: make a communication between my android app and the modem/router.
My question is:
Do I have to program an app on the server side to do this job, or is there an app already available?
If none are available, could you please tell me the steps to create one, or any references to that end?
Thank you!
I think your best bet is to use a dynamic dns service. That will allow you to give your machine a string name, run the app they'll give you (or many routers support this built-in), and just reference the computer by name when you need it. See http://en.wikipedia.org/wiki/Dynamic_DNS

Categories

Resources