Applet Servlet socket communication on tomcat5.0..plzz help I AM GETTING NULL POINTER EXCEPTION/JAVABIND EXCEPTION:CODING HAS BEEN ENCLOSED HERE WITH
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sakshi_opopo
Posted On:   Tuesday, March 28, 2006 01:01 AM

In client side i am using applet On server side its servlet In Applet>>>>>>>>>>>> import java.awt.event.*; import java.net.*; import java.io.*; import java.security.*; import javax.swing.event.*; public class app extends JApplet implements ActionListener { JTextField tf1; JTextField tf2,tf3,tf4; JButton saveb,closeb; ObjectOutputStream out; ObjectInputStream in; InetAddress inet=null; Socket sock = null; //SocketPermission p; public void init() { Container conn=getContentPane();    More>>

In client side i am using applet

On server side its servlet


In Applet>>>>>>>>>>>>

import java.awt.event.*;

import java.net.*;

import java.io.*;

import java.security.*;

import javax.swing.event.*;


public class app extends JApplet implements ActionListener
{

JTextField tf1;
JTextField tf2,tf3,tf4;
JButton saveb,closeb;

ObjectOutputStream out;
ObjectInputStream in;

InetAddress inet=null;


Socket sock = null;
//SocketPermission p;


public void init()
{


Container conn=getContentPane();

conn.setLayout(new FlowLayout());

tf1= new JTextField(11);

tf2= new JTextField(11);
tf3= new JTextField(11);
tf4= new JTextField(11);
saveb=new JButton("save");
saveb.setActionCommand("save");
saveb.addActionListener(this);


closeb=new JButton("close");
closeb.setActionCommand("close");
closeb.addActionListener(this);


conn.add(tf1);
conn.add(tf2);
conn.add(tf3);
conn.add(tf4);


conn.add(saveb);
conn.add(closeb);
}// init



public void actionPerformed(ActionEvent evt)
{

if(evt.getSource()==saveb)
{

try {
//inet=InetAddress.getLocalHost();
sock=new Socket("127.0.0.1",9999);
tf1.setText("sock-CREATED"+sock);
getAppletContext().showStatus("1.socket created");
}

catch(BindException e)
{
tf1.setText("prob in sock of app is"+e);
}

catch(Exception e)
{ tf1.setText("io-sock prob"+e);
}


try
{

out=new ObjectOutputStream(sock.getOutputStream());

in=new ObjectInputStream(sock.getInputStream());

getAppletContext().showStatus("2.. Objects created");
}

catch(Exception e)
{
tf2.setText("prob in obj creation is"+e);
}




try
{

showStatus("before writting string to the serv 1");

out.writeObject("fromtheapp");
showStatus("after witting to the server 2");


}

catch(Exception e)
{
showStatus("prob in data sending is"+e);
}

try{
out.close();
in.close();
sock.close();
getAppletContext().showStatus(" 3.. CLOSED THE OBJ AND SOCKET");
}

catch(IOException e){
showStatus("prob in closing the socket is "+e);
}
}//if
} //action listener

}//class



On SERVER >>>>>>>>>>>>>>>>>>>>>>>>>>>

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

import java.net.*;

import java.util.*;


public class serv extends HttpServlet
{

ServerSocket ssoc;

Socket soc;

int port=9999;

ObjectOutputStream oos=null;
ObjectInputStream ois=null;
String msg;

//SocketPermission p;


public void init(ServletConfig sc) throws ServletException
{
super.init(sc);

}

public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException
{

doPost(request,response);
}

public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException
{
PrintWriter out = response.getWriter();

out.println("
in sock1 do post method");


try
{

ssoc = new ServerSocket(port);
soc=ssoc.accept();
}

catch(Exception e)
{out.println(" in creation of sock is"+e);
}


try{

out.println("socket accepted");

oos=new ObjectOutputStream(soc.getOutputStream());

ois=new ObjectInputStream(soc.getInputStream());

out.println("
value in server side socket is"+soc);
}


catch(Exception e)
{out.println(" in object creation is"+e);
}
try {

response.setContentType("text/html");

out.println(" in the servlet html ");

out.println(" ");
out.println(" ");

out.println(" html over ");
}
catch(Exception e)
{ out.println("in the 1 block of serv "+e);

}

out.println("begin to read in the serv--till now appp should be loaded");

try
{ out.println("before getting the string from applet");
String s=(String)ois.readObject();
if(s.equals("fromtheapp"))
out.println("got the string from the app");
}

catch(Exception e)
{

out.println("
prob in data serialization block ");

out.println(e.toString());
}


try {
oos.close();
ois.close();
soc.close();
out.println("destroyed the Objects");
}

catch(IOException e)
{

out.println("Exception in destroying of Objects is "+e);
}

}

}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>    <<Less
About | Sitemap | Contact