Java debug using socket vs shared memory - java

In Java development on Windows there are two different transports that can be used while debugging.
What are the advantages of using Socket transport on the same computer where the app is running?
I know Socket can work on a remote computer. But I am trying to figure out if it makes a difference on my local dev box vs Shared memory?
Thank you.
UPDATE: I am using Intellij IDEA.

Shared memory will be faster :-)
The only advantage of sockets on same machine I can think of is that you have the same, universal debugging protocol, so when you deploy your app to a remote server the only visible change will be the ip.

What are the advantages of using Socket transport (...)?
The advantage of using Socket transport on the same machine is to ignore incompatibilities between the IDE JDK and the application's (or web-application) JDK.
Example:
Connect to a application that run on JDK32-bit will fail if the IDE is running a JDK64-bit using shared memory. In this case:
You MUST use Socket on the same machine.

Related

How to make a java client use a socket to connect to a server not on my computer?

I know how to make a socket between a server and client if they are both on my computer. What I don't understand is how to make a socket connection between a client on my computer, and my server running on a different network. I can't just do:
new Socket("Machine name", PortNumber);
right?
You can create a socket with a hostname or ip address. However this does not work in Java applets: They typically are restricted to only connect to the machine the web page has been loaded from. Similar restriction (Java does this with a special SecurityManager) applies to some old fashioned and strict application servers.
But with stand-alone Java programs nothing is stopping you from doing it. If you have problems it might be best to tell us what error message you get.

How do you establish a connection to a server in Java?

I want to create an application which will connect to a file server and download a few video files. The server is a shared hosting Linux server.
I don't want code or anything like that, I just want to know whether this is possible and if so, what should I be researching. Should I be using java sockets? Or can Java sockets only connect to java based servers?
Should I be using java sockets?
Depends on the type of server you connect to. You can use an existing library which will abstract the interaction with the server for you (recommended) or implement the required protocol yourself (not recommended).
Can Java sockets only connect to java based servers?
Sockets in Java are just an interface to the native socket API of the OS you are on. Every program that connects to a server over the network has to use them, regardless of whether it is a C/C++/Python/Java/... application. So, to answer your question; no, "Java sockets" can connect to any server.
Read more about sockets in this Wikipedia article about sockets in general or this one about Berkeley sockets (the socket API implemented by most operating systems).

Java SSH Tunneling for an IRC chat

My program connects to an IRC room on freenode.net, it uses port 6667, apparently that port is blocked in my college so the project doesn't work there (I wish I had known that before I proposed that one, but it's due the next week so I can't make a new project now). I read that it was possible to tunnel that connection, but I'm not sure how to do it.
I read I had to use an SSH library but I can't find one that helps me tunneling the connection using a socket.
I found a package called ssh in MindTerm but a really old one, that basically does the process (I think) using these lines:
SSHSocketFactory fact = new SSHSocketFactory("ssh.freessh.biz", 22, new SSHPasswordAuthenticator("freessh", "7QO5dkmg<"));
ventanachat.socket = fact.createSocket(servidorirc, puerto);
It gives me: java.io.IOException: MindTerm do not support SSHv2 yet, enable SSHv1 compatibility in server
So I tried a new version that has ssh2 support, but I just can't get the same process since classes are different here and there's no documentation.
The socket is basically Socket socket = new Socket ("irc.freenode.net", 6667);
I am wondering what library could I use, and how?
You are liable to get into trouble for circumventing blocks of the IRC port.
I've got another idea. Download and install IRC server software on the machine you are doing development on. Then you should be able to connect to it from your client without anything blocking the port. (And if you still run into port problems, just configure the client and server use a different one.)
Alternatively, look at the answers to this SO question: Simple SSH Tunnel in Java
There's a couple of SSH libraries for Java present on the market and most of them support SSH tunneling. We offer SecureBlackbox product (Java edition) which has samples (including tunneling), documentation and support.
Ganymed and Jsch both support SSH tunnelling, and both are free.

How can I determine if another local machine is alive?

Is it possible to make my local computer function as a gateway in Java? I need the other local machines to connect directly to my computer to see if they are alive or not.
You could run a Java server program on your desired PC and let it listen on a port. Then you could use other programs (browser, other Java programs etc.) to connect to this port, and send commands to be executed by the Java server program.
If you just want to see if the PC is turned on or not, I'd just use the ping command though. Or see this answer: How to do a true Java ping from Windows?
Surely it's the other way round? Surely you want to connect to the other machines to see if they're alive? In which case see InetAddress.isReachable().
Try this.
Create a Java Server Socket, which keeps listening to the client at some port.
Write a client in Java which connects to the Server, wrap the connection logic in try-catch block....
If your host is alive the try code is executed which contains the code to connect to the
Server, if this connection process fails you will get UnknownHostException, here you can instead type a message that the connection failed.
You could more easily manage and control this by polling for other devices from a central server. If possible, avoid unnecessary client/agent apps that might tax your development and support resources as well as taking up RAM on the client workstations.
There are many monitoring tools that already do what you want. I'd have a look at Nagios, for example.
If you want to develop your own app, do your own quick troubleshooting, or just get a feel for network discovery tools, then take a look at NMAP. You could, for example, search a subnet for anything that responds to TCP:445 and see what Windows machines are alive.
If you do go the Nmap route, please have a look at Nmap4j on Sourceforge. It's a Java wrapper API that simplifies the work needed to integrate Java and Nmap.
Cheers!

GUI on top of a JVMTI agent

I am planing to develop a profiler by using the JVMTI API provided by Oracle. For a visualization I would like to implement a GUI (Qt framework) on top of the agent code. My first jvmti agent is aready compiling and running and I started to integrate the agent into my Qt project.
Now I am facing the problem how to couple agent with GUI. Should the GUI be launched inside the agent? For instance in the Agent_OnLoad function?
A long-term would be to start the profiling out of the GUI, though I cannot imagine how to realize that.
Well.. you have a number of choices the most obvious would be socket based comms. You'll have to assume that the majority of profiling use cases will involve a remote headless JVM on a server. In my profiler you can operate headless with a small start/stop/control utility on the same machine as the agent, data is collected on the server and transfered to the client for visualisation. You can also start the remote (or local) jvm with the agent and connect to the listening agent over a socket from the full GUI.. collecting over that socket to the client.
There is also the new "JVM Attach API" which allows you to "insert" an agent into an already running JVM, therefore if the target machine is UNI* then you could use ssh/scp from your GUI and script an sCP transfer of the agent to the server and SSH to initiate the attach.
So... sockets (IP and/or domain) and reuse that code from the GUI for a headless control/collection client

Categories