I want to disable the network for testing like this solution in c#: How to simulate network failure for test purposes (in C#)? It suggests setting the ip to a bogus static address. How can I set the ip from Java or Groovy?
This solution is for windows. I'm using Mac.
How about setting a proxy for the JVM that drops all the requests ?
You wouldn't have to change your system configuration, proxy handling could be done via fixtures if you want some advanced properties.
That seems to me a way to explore
Related
I'm trying to implement fully-automatic PCP (according to https://www.rfc-editor.org/rfc/rfc6887) for a decentralized P2P chat system.
That requires PCP configurations to be made, and so far I haven't found anyone having a library or framework for that. Now I'm trying to make my own, and here's the first hurdle:
How do I find the current system's Default Gateway IP on multiple OS types and if possible both IPv4 and IPv6.
I made myself a simple way of receiving and interpreting commands to the CLI of the host OS using
Runtime.getRuntime().exec("[COMMAND LINE]");
as Java itself seems to provide no such information, of if I don't know where.
The current plan would involve getting the ipconfig and ifconfig returns on Windows and Linux (for MAC i'm sure there is a similar command), then search for the keyword of "gateway" and find the next IPv4 and IPv6 addresses, then see if anyone answers there on UDP port 5351 after a few attempts. I'm fairly certain it could work, but before using try-and-error methods I want to look for a more professional solution.
On top of that it would be good having a way to find out if the system is inside a NAT. While it usually isn't a problem with the private A, B and C networks there always is the possibility of custom settings on the router like more configured private networks requiring NAT.
I am using windows 8 (64bit) but not able to get access to internet using netbeans. When I am trying to update via Help > Check for Update I am getting
Check your network connection, verify that your proxy settings are configured correctly in the NetBeans IDE, or try again later.
When I am trying to access some url with a program in java I am getting error
connection refused: Address is invalid on local machine
whats going on here????
I need to force Java to use IPv4, to do so set it by command
setx _JAVA_OPTIONS -Djava.net.preferIPv4Stack=true
Are you behind a proxy server? Go to Tools > Options > General and try to change the network settings according to your network config.
EDIT: It may also be a firewall issue.
Are you using a proxy server, because if you are then you will need to use a ProxyAuthenticator java class which will can be called within your Java class. This should allow your class to access the Internet.
However, it may be worth checking your NetBeans Internet settings (Tools -> Options -> General) and checking whether a HTTP Proxy authentication is being used. Even so, a ProxyAuthenticator Java class may still be required (assuming a Proxy server is being used). Please see Authenticated HTTP proxy with Java
I have 16 Java processes with the same main method and arguments running on one machine. I wish to monitor these remotely thru JConsole.
Hard coding port numbers like -Dcom.sun.management.jmxremote.port=5000 won't work because these processes are using same configuration and they can't work with same port.
Is it possible for the JVM to select a different port dynamically for each of the 16 processes?
Using RMI Connector might be the way as you may specify URL of your agent.
In case you'd need it, you may create RMI registry programatically using:
java.rmi.registry.LocateRegistry.createRegistry(port);
You may find following unrelated sample useful: Connecting Through Firewall Using JMX
I don't think the oracle jvm supports anything like this. the only thing that might work is using the port "0", which enables "dynamic" port selection in some rmi related stuff.
I just set up a MySQL server on my PC for testing Java with JDBC.
At the moment "localhost" works perfectly as hostname for my applications, when running them on the same system.
However what would be the hostname for my MySQL server for applications that are running on different computers? Something like "my_ip:port" would work? I was thinking of writing an applet, which I could upload on a web server and try to connect to my database here. Is it possible to achieve that?
Something like "my_ip:port" would work?
If the MySQL instance has bound to your public interface, and if your firewall allows it, yes. If you connect to the 'net via a router that does NAT (for instance, a combined DSL modem and wireless router allowing you to connect multiple computers), you'll have to set up forwarding rules in the router to tell it which of the local machines to forward requests to.
You don't have to use an IP address. Your machine will also probably have a host name of some kind (either one you've assigned or, if you connect through an ISP, more likely one they've assigned). That would work too.
I was thinking of writing an applet, which I could upload on a web server and try to connect to my database here. Is it possible to achieve that?
With a signed Java applet, yes; otherwise, no. That's because the security sandbox that Java applets run in doesn't let them access servers other than the one they were loaded from (the web server).
A much better approach is to have your client-side code (Java applet, or just DHTML+Ajax stuff) talk to server-side code on the web server, which in turn talks to your DB. That way, the DB is never directly exposed to the outside world, and you don't have to do things like signed applets.
You can always use the ip address of the server running mysql as the hostname or its fully qualified domain name.
That should work, but you also should consider port-forwarding through your firewall.
Go here to get your IP: http://www.whatsmyip.org/
The port is the port mysql is setup on.
I'm trying to get a BACNet scanner up on an Seimens server running the Apogee system with a BACNet interface. I've tried using BACNet4j put i get a port bind error on the LocalDevice object for test/Scan.java.
Does anyone know of any other libraries I could use or a reference to instructions for setting up a BACNet plugin to a building management system?
I have had the same problem before, i.e. the BACnet client needs to both send and receive from UDP port 47808. Since the BACnet server already uses that port to listen (and reply) my solution was to use a virtual IP (a bridge) so that my client runs on the same Ethernet card but with a different IP address. A bit convoluted, I know, but it works.
Whether or not the Apogee system supports virtual (or simply additional) network drivers is another question altogether. On my Linux and Windows machines I can run as many servers and clients as I need (I actually don't know what is the limit, I have run up to 5 servers and 3 clients without any problems).
Concerning the port bind error, you may have to configure your firewall because:
BACnet/IP is using UDP
the default port number is 47808 (0xBAC0)
Your issue might be the use of a (BACnet port #) socket that is already in-use; you have to ensure that it's not in exclusive-use - before binding to the socket, but also (slightly more) important, also ensure it's marked for reuse.
But unless you're listening for Who-Is broadcasts, I'd recommend listening for the (unicast) responses upon a different port #, e.g. 0xBAC1/47809, but still send upon the standard port # 0xBAC0/47808.