#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2006
    Posts
    29
    Rep Power
    0

    Client control server's parallel port via jsp..help..


    Hi everyone:

    I m not sure wheather i post at the right place.. but i have no idea..


    My problem:
    I need to complete a project which required controlling pc(server) parallel port remotely, via internet from another pc(client) with webpage interface.

    User will need to complete the registration form in order to login and controlling the server side parallel port.

    i just ignore the registration side first since i hv an example about the database-related example from "Jakarta Struts for Dummies".
    www.dummies.com/go/jakarta

    And now i need to create a simple jsp, with servlet which will enable client to set or reset the parallel port.
    Here is an example about controlling the parallel port remotely,
    http://www.epanorama.net/circuits/parallel_output.html
    but it run a program called portcontrol.exe with php, i need to controlled it without such .exe program.

    I have successfully tested program below to set the bit0 of parallel port, but in java.
    --------------------------------------------------------------------------------------------------
    import parport.ParallelPort;
    class SimpleIO {
    public static void main ( String []args )
    {
    ParallelPort lpt1 = new ParallelPort(0x378); // 0x378 is normally the base address for the LPT1 port
    int aByte;
    aByte = 0x01; // a simple and irrelevant operation
    lpt1.write(aByte); // write a byte to the port's DATA pins
    System.out.println("Output to port: " + aByte);
    }
    }
    -----------------------------------------------------------------------------------------------

    but .. how to "put" these program into .jsp so it can controll by client?
    let say.. the page will provide a button, and when it pressed, server will
    set it parallel port's bit0.


    I have set up a tomcat web-server.

    I m still beginner in jsp and servlet programming, and i really need help from all of you. please guide.
    Thanks in advance.
  2. #2
  3. action=(isSleep())?sleep:code;
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Sydney->Indiana
    Posts
    182
    Rep Power
    15
    There is simply no way (short of exploiting a vulnerability) that you can access this via pure jsp. Remember jsp to the client is simply http. Looks like you'll need a signed applet (if you want to use java) so that you can perform those low level system calls and use that applet to communicate back to your originating server.

    HTH,
    W
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2006
    Posts
    29
    Rep Power
    0

    how about servlet..applet ?


    Hi:

    .. how about do it with jsp n servlet ? ..

    .. anybody know it is possible to "convert" a java program
    to applet in simple way? ..or maybe it can be implemented in applet ?

    please help ..
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2006
    Posts
    29
    Rep Power
    0

    Simple server with parallel control


    By running the java program below, once client access to
    http://localhost:7170, it will set server's parallel port bit0 to high.

    I wish to change it to servlet (maybe with jsp) and hv a graphic interface which enable client to set bit(s) of parallel port.

    Any idea on modified the code? Please guide me the steps needed...

    Thanks a lot . !!



    Code:
     import java.net.*;
       import java.io.*;
       import java.util.*;
       import java.lang.*;
       import parport.ParallelPort;
       import java.util.Date;
       import java.util.Calendar;
       import java.text.SimpleDateFormat;
       import java.util.*;
        public class httpServer_io 
       {
           public static void main(String args[]) {
             int port;
             ServerSocket server_socket;
             try { 
                port = Integer.parseInt(args[0]);
             }
                 catch (Exception e) {
                   port = 7170;
                }
             try {
                server_socket = new ServerSocket(port);
                System.out.println("httpServer running on port " + 
                   server_socket.getLocalPort());
             // server infinite loop
                while(true) {
                   Socket socket = server_socket.accept();
                   System.out.println("New connection accepted " +
                      socket.getInetAddress() +
                      ":" + socket.getPort());
                // Construct handler to process the HTTP request message.
                   try {
                      httpRequestHandler request = 
                         new httpRequestHandler(socket);
                   // Create a new thread to process the request.
                      Thread thread = new Thread(request);
                   // Start the thread.
                      thread.start();
                   }
                       catch(Exception e) {
                         System.out.println(e);
                      }
                }
             }
                 catch (IOException e) {
                   System.out.println(e);
                }
          }
       }
        class httpRequestHandler implements Runnable
       {
          final static String CRLF = "\r\n";
          Socket socket;
          InputStream input;
          OutputStream output;
          BufferedReader br;
       // Constructor
           public httpRequestHandler(Socket socket) throws Exception 
          {
             this.socket = socket;
             this.input = socket.getInputStream();
             this.output = socket.getOutputStream();
             this.br = 
                new BufferedReader(new InputStreamReader(socket.getInputStream()));
          }
       // Implement the run() method of the Runnable interface.
           public void run()
          {
             try {
                processRequest();
             }
                 catch(Exception e) {
                   System.out.println(e);
                }
          }
           private void processRequest() throws Exception
          {
             while(true) {
                String headerLine = br.readLine();
                System.out.println(headerLine);
                if(headerLine.equals(CRLF) || headerLine.equals("")) 
                   break;
                StringTokenizer s = new StringTokenizer(headerLine);
                String temp = s.nextToken();
                if(temp.equals("GET")) {
                   ParallelPort lpt1 = new ParallelPort(0x378); // 0x378 is normally the base address for the LPT1 port
                   int aByte;
                
                
                //aByte = lpt1.read(); // read a byte from the port's STATUS pins
                   aByte = 0x01; // a simple and irrelevant operation
                   lpt1.write(aByte); // write a byte to the port's DATA pins
                   System.out.println("Output to parallel port: " + aByte);
                
                //System.out.println("Input from parallel port: " + aByte);
                // Get today's date
                   Calendar now = Calendar.getInstance();
                   SimpleDateFormat formatter = new SimpleDateFormat("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
                   System.out.println(" It is now : " + formatter.format(now.getTime()));
                   System.out.println();
                // Construct the response message.
                   String serverLine = "Server: fpont simple java httpServer";
                   String statusLine = null;
                   String contentTypeLine = null;
                   String entityBody = null;
                   String contentLengthLine = "error";
                   statusLine = "HTTP/1.0 200 OK" + CRLF ;
                   System.out.println("statusLine: "+statusLine);
                   contentTypeLine = "text/html" ;
                   entityBody = "<HTML>" + 
                      "<HEAD> <TITLE> I/O port </TITLE> </HEAD>" 
                      +" Simple HTTP Server <br> "+formatter.format(now.getTime()) 
                      +"<br> I/O port - Status:"+aByte+"<br> StatusByte< ";
                   int i = 256; //max number * 2
                   while( (i >>= 1) > 0) {
                      System.out.print(((aByte & i) != 0 ? "1" : "0"));
                      entityBody +=(((aByte & i) != 0 ? "1" : "0"));
                   }
                   entityBody += "><br>";
                   contentLengthLine = "Content-Length: " 
                      + (new Integer(entityBody.length()).toString() )
                      + CRLF;
                // Send the status line.
                   output.write(statusLine.getBytes());
                // Send the server line.
                   output.write(serverLine.getBytes());
                // Send the content type line.
                   output.write(contentTypeLine.getBytes());
                // Send the Content-Length
                   output.write(contentLengthLine.getBytes());
                // Send a blank line to indicate the end of the header lines.
                   output.write(CRLF.getBytes());
                   System.out.println("\nentityBody: "+entityBody);
                   output.write(entityBody.getBytes());
                }
             }
             try {
                output.close();
                br.close();
                socket.close();
             }
                 catch(Exception e) {}
          }
       }
  8. #5
  9. AYBABTU
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Here or There
    Posts
    1,256
    Rep Power
    376
    A JSP gets compiled server-side into a servlet, so combining them is possible, but doesn't make much sense. What is a better option is that you create a JavaBean that handles the parallel port controlling and from your JSP you access this bean. If you do a search on something like "using JavaBeans in JSP" you should get many examples on how to do this.
    A common mistake people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
    Douglas Adams
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2006
    Posts
    29
    Rep Power
    0
    Ok, thanks for your advices.
    I will try Java Bean ..

    If there is any alternatives idea suggest to me too,
    thanks.

IMN logo majestic logo threadwatch logo seochat tools logo