gini gini
Posts: 1
Nickname: sakshi
Registered: Mar, 2006
applet-servlet socket communication
Posted: Mar 10, 2006 2:43 AM
Advertisement
plzz help me out to make servlet applet socket communication .I am getting null pointer exception I am doing at tomcat5.0.28,using j2sdk1.4._03,using serialization the code for APPLET IS AS:- import java.awt.*; import javax.swing.*; import java.net.*; import java.security.*; import java.io.*; public class applet extends JApplet { static int port; public void init() { showStatus("Initialising..."); Socket sock = null; //port=Integer.parseInt(getParameter("Port")); ObjectOutputStream out; ObjectInputStream in; showStatus("Creating Socket..."); try { sock=new Socket(getCodeBase().getHost(),9999); out=new ObjectOutputStream(sock.getOutputStream()); in=new ObjectInputStream(sock.getInputStream()); } catch(Exception e) { showStatus("Error in opening Client Socket..."+ e.getClass().getName() + ": " + e.getMessage()); } }//init() } ****************************************** CODE FOR SERVLET IS:- ************************************************** import java.awt.*; import javax.swing.*; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.*; import java.security.*; public class servlet extends HttpServlet { ServerSocket serverSock; Socket clientSocket; int port=9999; ObjectOutputStream oos; ObjectInputStream ois; public void init(ServletConfig sc) throws ServletException { super.init(sc); try { serverSock = new ServerSocket(port); } catch (IOException e) { System.out.println("Could not listen on port: 6001"); } } public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html><head><title> HCL InfoWall </title></head>"); out.println("<APPLET CODE=applet.class WIDTH=760 HEIGHT=375>"); //out.println("<PARAM NAME=Port VALUE = 6001>"); out.println("</APPLET></HTML>"); try { clientSocket = serverSock.accept(); } catch (IOException e) { out.println("Accept failed: 6004"); } try{ oos=new ObjectOutputStream(clientSocket.getOutputStream()); ois=new ObjectInputStream(clientSocket.getInputStream()); } catch(Exception e) { out.println("Objects in[put-output not Initialize becoz:"+e); } out.close(); }//doget }//class THANKS IN ADVANCE..PLZZ HELP ME OUT..OR SEND THE SIMPLE EXAMPLE WHICH I CAN DIRECTLY TRY OUT THANKS AGAIN