Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
76
rated 0 times [  78] [ 2]  / answers: 1 / hits: 24837  / 9 Years ago, fri, november 27, 2015, 12:00:00

I have a Java web application that needs to know the computer name of clients connecting to it. My first idea was to get it via JavaScript and fill a hidden form field with it, but after some digging, it appears JS cannot access that information.



Then I tried using an applet and accessing the applet methods via JavaScript. This seems to work on Firefox, but newer Chrome versions don't run applets.



Then I considered switching to a Java Webstart application, which, as far as I know, should work under Chrome, but in this scenario, since the Webstart application runs outside the browser,JavaScript cannot access its methods.



Then I tried saving the hostname in the environment TEMP directory, which works, in Firefox + Linux + Java7, but not in Firefox + Windows + Java8: the applet just doesn't run, and, in addition, I haven't found a way to access the defined TEMP directory and read the file in JavaScript.



At this point I'm out of ideas and would love to have some input from you guys. Any hints on how to achieve this? Did I miss any obvious solution?



Please notice I need the computer defined hostname, not what the computer's IP resolves to via DNS.



Thanks.


More From » java

 Answers
58

Your Javawebstartet Application could Host Websocket listener. So you could access this application via Websocket from javascript. Works only with http, not https



On JavaSide use the websocket implementation of http://java-websocket.org/



In Javascript I use https://code.google.com/p/jquery-websocket/
You can find examples there too.
The websocket communication is async. Create the WS with the callback method for the response



var ws = $.websocket(ws://127.0.0.1: + lport + /, {
events: {
say: function (e) {
//showMsg(e.data);

}
}
});


and call the server with



ws.send(0, jsonData)

[#64249] Wednesday, November 25, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
larrycodys

Total Points: 394
Total Questions: 93
Total Answers: 78

Location: Romania
Member since Mon, Jun 6, 2022
2 Years ago
;