I want to implement a small multiplayer client/server game. It's my concurrent program project. I wrote the application's basic logic in Java and it's working. I want to make it web based. I am not sure how to do it. Here is a small part that I want to implement:
<%@page import="javacode.Client"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
Client client = new Client();
boolean b = client.connect();
%>
<%= b%>
<script type="text/javascript"></script>
<script type="text/javascript">
function sendToServer(){
var line = document.getElementById("input").value;
//send line to server using client.send()
client.send(line);
//get response from server to client using client.get()
line = client.get();
document.getElementById("input").value=line;
}
</script>
<html>
<head></head>
<body>
<br>
<input type="text" name="input" id="input"/>
<input type="button" value="send" onclick="sendToServer()"/>
<input type="text" name="output" id="output" />
</body>
</html>
I am starting a chat echo server then opening this JSP page. It's connecting to the server by creating a client object. But I want to use the same client object for further communication with the server. Whenever I click the send button it has to get an input field's value and send it to the server, then get the response from the server with the client.get() method and set the value to output field. As a Java program Client.java is working fine, but I am not sure how to do it web based.
PS: I don't want to use an applet.