Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How to fetch an AJAX call on a LAN machine?  (Read 1521 times)
0 Members and 1 Guest are viewing this topic.
Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Posted 2013-01-25 11:49:34 »

Hi.

This is not homework. Its an assignment at my internship, and I've been appointed a task I haven't tried before. I have to send an AJAX call from a server machine, and then fetch it and use an integer in that AJAX call to change a variable, in a Javascript running in a browser on the client.

I've never done AJAX calls through a local area network before. How would I go about it?

- Jonas
Offline meingrosserfreundjo

Senior Newbie





« Reply #1 - Posted 2013-01-25 13:02:40 »

Not much different than you would do on the internet. The Server has to run some kind of Web-Server that can accept and process requests that you send to it. So instead of sending the AJAX Request to a certain homepage you prepare your Webpage (or whatever you want) to send it to the IP-Adress of that Server.

Is there something specific you want to know about?

Edit: Re-read your post. Do you mean to send an AJAX response to the client without a foregoing request of that client?
Offline kulpae

Senior Newbie


Exp: 9 years



« Reply #2 - Posted 2013-01-25 13:11:25 »

exactly. You simply connect to the IP. Or if you wish to access the server by name, you can link an alias to IP in the hosts file and then access the server by this alias.
AJAX is no different than normal HTTP, it's only issued asynchronously by the client. If you want your server to talk back to the client, you have to hold the connection open, until there is a message from the server. But still the connection is issued by the client, see http://en.wikipedia.org/wiki/Comet_(programming) .
Or simply use WebSockets (HTML5) if allowed.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #3 - Posted 2013-01-25 13:22:42 »

Not much different than you would do on the internet. The Server has to run some kind of Web-Server that can accept and process requests that you send to it. So instead of sending the AJAX Request to a certain homepage you prepare your Webpage (or whatever you want) to send it to the IP-Adress of that Server.

Is there something specific you want to know about?

Edit: Re-read your post. Do you mean to send an AJAX response to the client without a foregoing request of that client?
Yes, without the client requesting it. Basically the client should change a number shown on a screen by a full-screen webbrowser, whenever it recieves a specified AJAX call with a value in it.
I intend to do some handshaking first, obviously. So the client connects to the server, and keeps the connection open, receiving AJAX calls at random, while the client continues to update the number on the screen to the last AJAX call received.

- Jonas
Offline meingrosserfreundjo

Senior Newbie





« Reply #4 - Posted 2013-01-30 15:52:08 »

Sry for late answer. Processing input form a server without a request is something that is not yet widely supported by current browsers. You could do something like a heartbeat-system where you let the client send a request every 30 seconds or so to the server that answers the number you would like to change.
It is (or has been) however afaik disregarded as bad practice because of the additional traffic that such requests cause. In your case though that would not matter because it is only LAN and only one single number that gets updated.

Another approach is a very long Request that stays open until a certain "Event" causes the Server to respond. After that the Client immediately sends another request, again waiting for the server to respond.

Wikipedia-Article Pointing

Also google spits out tons of information on that subject. Including some ready-to-use frameworks that use those approaches:

push ajax

Hope it helps  Wink
Offline sproingie

JGO Kernel


Medals: 202



« Reply #5 - Posted 2013-01-31 02:23:32 »

Actually, short polling tends to be more scalable, because long polling holds a socket open longer on the server, and fds are a more scarce resource than bandwidth. 

Not that it's likely to matter that much on a LAN scale.
Offline meingrosserfreundjo

Senior Newbie





« Reply #6 - Posted 2013-01-31 08:41:07 »

Actually, short polling tends to be more scalable, because long polling holds a socket open longer on the server, and fds are a more scarce resource than bandwidth. 

Not that it's likely to matter that much on a LAN scale.


As sproingie said, considering that you want to implement this in a LAN environment it doesn't matter much which option you choose.
What you might think about though is that with the first method (polling every x seconds) you have a chance of the client having the wrong number for quite some time (bit less than x seconds in the worst case). Using the second method you have the new number on the client always only short time after the server has the new number (since it's the server that can then complete request whenever he wants - e.g. when he has a new number to send)
Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #7 - Posted 2013-01-31 14:41:03 »

Hi guys.

Thanks for the inspiring thoughts. I ended up doing something...alternative.

Seeing as this project is terribly limited (I have to choose 1 browser to work with, it has to be under Windows, and all information, connections and code must be available directly through the browser, with little to no load-time on any Internet connection), I ended up creating and embedding a small Java applet, which simply holds a ServerSocket running, and whenever we send it a message via LAN, it requests the remote server for the queue-number, and sends it to the JavaScript, which can then use it to draw the new number. Using a bit of concurrency trickery on the server, I should never be without the right number on the screen for more than a few ms.

I realize there are ways to get around the spiderweb of "origin policy", but this seemed the most unintrusive way to me. At least I'm not going to violate any security protocols in any browsers anymore, and applets are already fully allowed on the client-PCs.

- Jonas
Offline sproingie

JGO Kernel


Medals: 202



« Reply #8 - Posted 2013-01-31 16:51:39 »

The applet trick is something I did before there was ever such a thing as "AJAX".  I coulda invented web 2.0, but a) I'm sure thousands of others had the same idea, and b) I wasn't any good at swindling the VCs who were already pulling out right before the dotcom crash. Tongue

Oddly enough, since LiveConnect was so awful, my first demo prototype used a flash 5.0 applet for the socket instead of java.

Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #9 - Posted 2013-01-31 17:17:41 »

So the applet-thing is a tried and true, but sort of old-school solution, then?

- Jonas
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline sproingie

JGO Kernel


Medals: 202



« Reply #10 - Posted 2013-02-01 01:48:22 »

"Tried", yes.  "True" would imply that it worked at all well, which as my experience showed, was not the case.
Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #11 - Posted 2013-02-05 19:15:22 »

Hmm...I'll keep that in mind, thanks. It seems to be working fine for my small project here at the moment, though. It'll only ever communicate with 2 computers anyway. 1 LAN and 1 server.

- Jonas
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (22 views)
2014-09-19 03:14:18

Dwinin (35 views)
2014-09-12 09:08:26

Norakomi (62 views)
2014-09-10 13:57:51

TehJavaDev (89 views)
2014-09-10 06:39:09

Tekkerue (44 views)
2014-09-09 02:24:56

mitcheeb (65 views)
2014-09-08 06:06:29

BurntPizza (48 views)
2014-09-07 01:13:42

Longarmx (35 views)
2014-09-07 01:12:14

Longarmx (40 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!