I want to implement a java server and a php client. Every time a click is done on the website (php client) a action should be executed on the server.
Actually my server looks like:
public static void main(String args[]) {
System.out.println("Signal Server is running.");
try {
socket = new ServerSocket(port);
while (true) {
connection = socket.accept();
InputStreamReader inputStream = new InputStreamReader(connection.getInputStream());
DataOutputStream response = new DataOutputStream(connection.getOutputStream());
BufferedReader input = new BufferedReader(inputStream);
command = input.readLine();
response.writeBytes(responseStr);
response.flush();
System.out.println("Running");
}
} catch (IOException e) {
System.out.println("Fail!: " + e.toString());
}
System.out.println("Closing...");
}
My HTML site looks like:
<?php
if (isset($_POST["Btn1"])){
$address = "localhost";
$port = 4343;
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$message = 'blablabla';
socket_connect($socket, $address, $port);
socket_sendto($socket, $message, strlen($message), 0, $address, $port);
};
?>
<html>
<head>
<title>Test</title>
</head>
<body>
<form id="form1" method="POST">
<button type="submit" form="form1" id="Btn1" name="Btn1" value="Btn1" title="Btn1">
Btn1</button>
</form>
</body>
</html>
My problem is, whats the best way to delegate the actions to the server. A little example, I have a method on my java server which posts "Hello" to the console. Now I click on a button on my website and this method should be executed. What is the best way to do?
Can I use my approach or is there a better one?