1

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.

5
  • 1
    Check out nodejs and socket.io Commented Nov 17, 2012 at 9:46
  • all those will be new to me. can't we do it using jquery/javascript and jsp? Commented Nov 17, 2012 at 14:54
  • Those have a fairly short time of learning curve, you are familiar with jquery and javascript which is an advantage for you. It is your decision, of course it can be made. Have a read this: stackoverflow.com/questions/6200869/… Commented Nov 17, 2012 at 15:03
  • my project deadline is even shorter :( i have only 2 weeks of time. any suggestions how to do it? I have tried with jquery but everytime i send request to jsp page, it creating new object. Commented Nov 17, 2012 at 15:36
  • i have solved it by storing client object in session variables Commented Apr 20, 2013 at 13:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.