0

Okay, so I have an apache server that has text/data that I want to sendoff to a Java client. The issue is that the data will change often, and I don't want the client to constantly do a read on the server, because obviously I don't want a constant ping. I know that I can make a client socket but that requires my users to port forward to access the server, which isn't going to work for my users.

What I've found online is UDP punching may work or NAT Transfer, but I cant find any examples for how to do it in Java.

  • If you have any questions please feel free to comment :)
DrBrad
  • 305
  • 2
  • 13
  • Can't you use server sent events or websockets? – frz3993 Apr 14 '17 at 20:35
  • I havn't found anything that will allow the server to respond randomly to the client. Because its an apache webserver I don't think you can do events.? – DrBrad Apr 14 '17 at 20:38

1 Answers1

1

You could Recieve Server-Sent Event notifications, in which the server send the data, using PHP and JS as an example:

var source = new EventSource("demo_sse.php");
source.onmessage = function(event) {
    document.getElementById("result").innerHTML += event.data + "<br>";
};

PHP:

<?php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');

$time = date('r');
echo "data: The server time is: {$time}\n\n";
flush();
?>