• Post Reply Bookmark Topic Watch Topic
  • New Topic

Socket ObjectStream is Accesible only once  RSS feed

 
Shantanu Gangakhedkar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends,
Hello Friends Problem is I am Deleoping Client/Server Application using Sockets. I am not getting I am able to access The Object stream only once. Sendin times it gives error. I want to access the Method mCommunicate in the Same Thread and from the GUI Application.
But when i access the method i Get "NullPoniterException" . I think problem is my ObjectStreams are getting Reset.
Please go thro code, and Reply me

public class ClientApplication
{
Socket client = null ;
Socket clientnew = null;
String UserName = null;
String Pwd = null;
Vector vc = null;
public cmsborrower[] cbm = new cmsborrower[5];
ClientThread CThread = null;
public ClientApplication(String mstrUser,String mstrPass)
{
UserName = mstrUser;
Pwd = mstrPass;
vc = new Vector();
vc.addElement(UserName);
vc.addElement(Pwd);
}

public void Connect()
{
try
{
client = new Socket("cil",2001);
clientnew = client;
CThread = new ClientThread(client,vc);
CThread.start();
}
catch ( SocketException se)
{
System.out.println("Exception in Socket Occured....");
}
catch ( UnknownHostException uhe )
{
System.out.println("Unknown Host....");
}
catch (IOException ex)
{
System.out.println("IO Exception..." + ex.getMessage());
};
}
public void mCommProcess(String sql,int SendReceiveQuit) {

}
}
class ClientThread extends Thread {
Socket clientSocket = null;
OutputStream req = null;
ObjectOutput reqobject = null;
InputStream res = null;
ObjectInput resobject = null;
Vector vc = null;
public cmsborrower[] cbm = new cmsborrower[5];
public ClientThread(Socket client,Vector v){
this.clientSocket = client;
this.vc = v;
}

public void run(){
try{
System.out.println("UserName:- " + vc.elementAt(0));
System.out.println("Pwd :- " + vc.elementAt(1));
req = clientSocket.getOutputStream();
reqobject = new ObjectOutputStream(req);
res = clientSocket.getInputStream();
resobject = new ObjectInputStream(res);
int errcode = 0;
String servmess = "3400";
reqobject.writeObject(vc);
reqobject.flush();
cbm = (cmsborrower[])resobject.readObject();
ReceiveBorrower borr = new ReceiveBorrower();
borr.cbmrec = cbm;
for(int i=1;i<cbm.length;++i)>
{
System.out.println("Values :- " + cbm[i].cbm_borrowcode + " | " + cbm[i].cbm_constcode + " | " + cbm[i].cbm_sectorcode);
}
}
catch(ClassNotFoundException ce)
{
System.out.println("Class not found...");
}
catch(IOException ioe)
{
System.out.println("IO Exception..." + ioe.getMessage());
}
catch(NullPointerException ne)
{
System.out.println("NullPointer..." + ne.getMessage());
}

String sql = "select * from cms_borrower_m where cbm_borrocode = 'TEMP00000010'";
System.out.println("Wrting String Object 1");
mCommunicate(sql,1);
}

public void mCommunicate(String sqlQuery,int iSendReceiveQuit)
{

switch(iSendReceiveQuit)
{
case 1 :
try
{
System.out.println(sqlQuery);
reqobject.writeObject(sqlQuery);
reqobject.flush();
}
catch (IOException ex)
{
ex.printStackTrace();
// System.out.println("IO Exception..." + ex.getMessage());
}

break;
case 2 :
/* try
{
cbm = (cmsborrower[])resobject.readObject();
ReceiveBorrower borr = new ReceiveBorrower();
borr.cbmrec = cbm;
for(int i=1;i<cbm.length;++i)>
{
System.out.println("Values :- " + cbm[i].cbm_borrowcode + " | " + cbm[i].cbm_constcode + " | " + cbm[i].cbm_sectorcode);
}
}
catch(ClassNotFoundException ce)
{
System.out.println("Class not found...");
}
catch(IOException e)
{
System.out.println("IO Exception..." + e.getMessage());
} */
break;
case 3 :
mDisConnectFromServer();
break;
default :
break;
}
}
public void mDisConnectFromServer()
{
try
{
reqobject.close();
resobject.close();
clientSocket.close();
}
catch ( IOException ex )
{
System.out.println("I/O Exception Occured..." + ex.getMessage());
}
}
}
 
Pawel Veselov
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can u tell what exact line throws the exception ?

------------------
With best of best regards, Pawel S. Veselov ( aka Black Angel )
 
Shantanu Gangakhedkar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error is on this Method mCommunicate of the ClientThread Class at line reqobject.writeObject(sqlQuery);
------------------------------------------------
System.out.println(sqlQuery);
reqobject.writeObject(sqlQuery);Exception(NullPointerException)
reqobject.flush();
 
Pawel Veselov
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a result of executing your class file:
<pre>
[vps@druid]~/jprogs$ java ClientApplication
UserName:- vps
Pwd :- vps
IO Exception...InputStream does not contain a serialized object
Wrting String Object 1
select * from cms_borrower_m where cbm_borrocode = 'TEMP00000010'
[vps@druid]~/jprogs$
</pre>
And this is what server told me:
<pre>
[vps@druid]~$ socket -s 2001
?�
asd
tAselect * from cms_borrower_m where cbm_borrocode = 'TEMP00000010'
[vps@druid]~$
</pre>
So, everything is fine.
It's really very strange if you get this exception in this place, since references can't became [null] without any reason.
So, I believe you should add some debug output there...
 
Shantanu Gangakhedkar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is no problem if i call the mCommunicate() method of Clientthred class from Run Method of the Same Class.
When I call mCommunicate method from ClientApplication's mCommProcess then it gives the Error. NullPointerException because the Streams are not available there I Think.
You please Access the mCommunicate() method from ClientApplications mCommProcess() method it gives error. and Remove the Call to mCommunicate() method from Run Method.
There lies the Error.Please help me
Thanx in advance and for ur replies
Shantanu
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!