Connection reset exception

hi,

iam trying to transfer the data from the client machine to the server. while getting the data,ie readLine method of the bellow code iam getting the Connecction reset error please help me.

import java.net.*;

import java.io.*;

import java.util.*;

import java.sql.*;

//sample CODE checking into VSS server

publicclass Serverimplements Runnable

{

private Thread getMes;

privatestatic ServerSocket ss;

private Socket soc;

private String dataIn,dataIn1;

private Send send;

private Insertion insert;

private CallInsertion callinsert;

private ArrayList headerList;

/* Call summary data here */

private ArrayList CheaderList;

private ArrayList CdataList;

private String Cdata;

public String agent;

public DataOutputStream dos;

private EncDec codec =new EncDec();

int numApp = 0;

private String newdataIn="";

public String firstData;

public String agentid;

public String agencyid;

private String genappdata;

private String genappdataWOED;//instance variable to hold the decrypted ACKNOWLEDGEMENT

private ArrayList updatePullStatus =new ArrayList();//For decrypting the ACKNOWLEDGEMENT

private ArrayList headerDetails =new ArrayList();

//Time variables added here

long t1,t2,diff,t3;

java.util.Date val;

public Server(Socket soc)

{

val=new java.util.Date();

t1= System.currentTimeMillis();

System.out.println("EXECUTION time starts at \t:"+t1+"\n");

this.soc = soc;

System.out.println("Client connected!\n" + soc);

getMes=new Thread(this);

getMes.start();

}

/*

*These method is responsible for understanding the header data incoming and decide whether to wait

*for recieve data or just send the data. Also will verify the user connecting to the server

*program.

*/

publicint getNumApps(ArrayList headerList)

{

if(headerList.size()>=5)

{

headerDetails = codec.decrypt(headerList);

try

{

Integer inte =new Integer(headerDetails.get(3).toString());

return inte.intValue();

}

catch(NumberFormatException npe)

{

//System.out.println("Number Of Application is not a number :"+headerDetails.get(3));

return 0;

}

}

else

{

return 0;

}

}

public String transType(ArrayList headerList)

{

if(headerList.size()>=5)

{

headerDetails = codec.decrypt(headerList);

return headerDetails.get(2).toString();

}

else

{

return"N";

}

}

public String userID(ArrayList headerList)

{

if(headerList.size()>=5)

{

headerDetails = codec.decrypt(headerList);

return headerDetails.get(1).toString();

}

else

{

return"Invalid User";

}

}

public String agencyid(ArrayList headerList)

{

if(headerList.size()>=5)

{

headerDetails = codec.decrypt(headerList);

return headerDetails.get(4).toString();

}

else

{

return"Invalid Insid";

}

}

public String agentid(ArrayList headerList)

{

if(headerList.size()>=5)

{

headerDetails = codec.decrypt(headerList);

return headerDetails.get(0).toString();

}

else

{

return"Invalid agentid";

}

}

publicvoid run()

{

String ackRec;

try

{

/* Reading from socket and printing data to the console */

System.out.println("Waiting for data . . .");

DataInputStream dis1=new DataInputStream(soc.getInputStream());

firstData=dis1.readLine();//HERE IAM GETTING THE ERROR.

ArrayList firstList = Splitter.split(firstData,"$$");

String header = firstList.get(0).toString();

//System.out.println("Header Data is \n" + header);

headerList = Splitter.split(header,"^");

numApp = getNumApps(headerList);

agencyid = agencyid(headerList);

agentid = agentid(headerList);

if(!(header.equals("")))

{

if(numApp>=0 )

{

dataIn = firstList.get(1).toString()+"$$";

newdataIn = dataIn.substring(1);

//System.out.println("Dat In :"+dataIn);

int i=1;

while(i<numApp)

{

String temp = dis1.readLine();

if(!(temp.equals("")))

{

dataIn = dataIn +temp;

i++;

}

}

}

if(numApp >0)

{

insert =new Insertion(dataIn);

ackRec= insert.insertIntoTable();

}

else

{

ackRec ="A*#";

}

/* Reading from database and putting data into socket */

dos=new DataOutputStream(soc.getOutputStream());

/************* COM2 *****************/

//System.out.println("Acknowledgement :"+ackRec);

dos.writeBytes(ackRec+"\n");

dos.flush();

//System.out.println("Written records :"+ackRec);

}

if(transType(headerList).equals("R") || transType(headerList).equals("B"))

{

send =new Send(userID(headerList),soc,agentid,agencyid);

genappdata=send.generate_appdata();

//System.out.println("Pushing appstatus data to PALMclient>"+ genappdata);

/************ COM3 ********************/

dos.writeBytes(genappdata+"\n");

updatePullStatus.add(genappdata.substring(2,3));

genappdataWOED=genappdata.substring(0,2)+codec.decrypt(updatePullStatus).get(0).toString()+genappdata.substring(3);

System.out.println("Finished Processing data");

if(genappdataWOED.equals("D^N^$"))

{

String ack = dis1.readLine();

/*********** COM4 **********************/

send.UpdateAppStatus(ack);

System.out.println("Transmission successful!!");

}

/***************************************/

}//if for sending data

else

{

System.out.println("No data was sent\n");

}

}//TRY ending

catch(NullPointerException npe)

{

ackRec ="A*#";

//System.out.println("ACK null" +ackRec);

}

catch(IndexOutOfBoundsException iooe)

{

ackRec ="A*#";

//System.out.println("Array out of bounds: ");

}

catch(IOException ioe)

{

System.out.println(" error in run method");

System.out.println(ioe);

}

catch(Exception e)

{

//System.out.println("Exception in run()");

e.printStackTrace();

}

finally

{

try

{

//System.out.println("Finally The number of Apps recd. is "+ numApp +".\n");

soc.close();

}

catch(IOException ioe)

{

System.out.println("Trouble in closing the socket connection!!\n"+ioe);

}

}

}

publicstaticvoid main(String[] args)

{

Socket s;

try

{

ss=new ServerSocket(Integer.parseInt(args[0]));

System.out.println("Server Started-- Writes data from Palm Client into Cash on hand server");

while(true)

{

System.out.println("Waiting for palm client to connect . . .");

s=ss.accept();

new Server(s);

}

}catch(Exception e){}

}

}

[14393 byte] By [sathaa-vasta] at [2007-11-27 0:50:25]
# 1
Maybe you should try to write basic client to check if the problem come from your server or from your client application.
olivieroa at 2007-7-11 23:20:27 > top of Java-index,Core,Core APIs...
# 2

Connection reset means any of the following, depending partly on what the text of the exception says:

(a) the client is messing with Socket.setSoLinger() and then closing the socket

(b) there is a firewall in the way which is dropping the connection for some reason

(c) the reader has previously sent some data to the writer which the writer hasn't read but has closed the socket instead.

(d) there are also various OS-dependent possibilities such as running out of buffer space. See http://forum.java.sun.com/thread.jspa?threadID=748677 for more information about this.

ejpa at 2007-7-11 23:20:27 > top of Java-index,Core,Core APIs...