java - why won't my client side accept anymore input -


why won't client side accept anymore input, after inputing 1 fix message. client send fix message server side, , server check errors, , send message client if has errors or not on fix message.

the problem comes when try send fix message client side, prior sending one, won't allow me send anything.

client program

public class tcpclient {              public static void main(string[] args) throws ioexception {                 string serverhostname = new string ("wa1235"); //127.0.0.1                  if (args.length > 0)                    serverhostname = args[0];                 system.out.println ("attemping connect host " +                 serverhostname + " on port 57634.");                  socket echosocket = null;                 printwriter out = null;                 bufferedreader in = null;                  try {                     // echosocket = new socket("taranis", 7);                     echosocket = new socket(serverhostname, 57634);                     out = new printwriter(echosocket.getoutputstream(), true);                     in = new bufferedreader(new inputstreamreader(                                                 echosocket.getinputstream()));                 } catch (unknownhostexception e) {                     system.err.println("don't know host: " + serverhostname);                     system.exit(1);                 } catch (ioexception e) {                     system.err.println("couldn't i/o "                                        + "the connection to: " + serverhostname);                     system.exit(1);                 }              bufferedreader stdin = new bufferedreader(new inputstreamreader(system.in));             string userinput;                  system.out.print ("input: ");              while ((userinput = stdin.readline()) != null) {                  out.println(userinput);                   system.out.println(in.readline());                  system.out.println(in.readline());                   if (userinput.equals("bye.")){                      system.out.println("exit program");                        break;                          }                     getvaluelog(parsefixmsg(userinput,userinput));                     system.out.print ("input: ");              }              out.close();             in.close();             stdin.close();             echosocket.close();             } 

server program

public static void main(string[] args) throws ioexception{         scanner console = new scanner(system.in);         system.out.println("type in csv file location: ");         //string csvname = console.nextline();           string csvname = "c:\\users\\downloads\\orders.csv";           serversocket serversocket = null;           try {               serversocket = new serversocket(57634);              }          catch (ioexception e)              {               system.err.println("could not listen on port: 57635.");               system.exit(1);              }           socket clientsocket = null;          system.out.println ("waiting connection.....");          try {               clientsocket = serversocket.accept();              }          catch (ioexception e)              {               system.err.println("accept failed.");               system.exit(1);              }           system.out.println ("connection successful");         system.out.println ("waiting input.....");          printwriter out = new printwriter(clientsocket.getoutputstream(),                                            true);          bufferedreader in = new bufferedreader(                  new inputstreamreader( clientsocket.getinputstream()));           string inputline, outputline;          while ((inputline = in.readline()) != null)              {               system.out.println ("server: " + inputline);                  if (inputline.trim().equals("bye.")) {                  system.out.println("exit program");                   break;                  }                scanner input1 = new scanner(new file(csvname));              scanner input2 = new scanner(new file(csvname));              scanner input3 = new scanner(new file(csvname));              scanner input4 = new scanner(new file(csvname));                string csvline = getcsvlineval (getlocation34csv(gettag34value(tag34location(gettagcsv( parsefixmsg(inputline ,inputline))), getvaluecsv( parsefixmsg(inputline ,inputline))), getval34(input1,  input2)), getcsvline( input3,  input4) );              outputline = compareclientfixcsv( gettagcsv( parsefixmsg(inputline ,inputline)), getvaluecsv(parsefixmsg(inputline ,inputline)), getcsvtag(csvline), getcsvvalue(csvline));               out.println(outputline);               input1.close();              input2.close();              input3.close();              input4.close();                }           out.close();          in.close();          clientsocket.close();          serversocket.close();      } 

method

public static string compareclientfixcsv(string[] ctag, string[] cvalue, string[] csvtag, string[] csvvalue){     int size = csvtag.length;     int size2 = csvtag.length;     int size3 = cvalue.length;     int size4 = csvvalue.length;     system.out.println("ctag size : " + size + ", csvtag: " + size2);     system.out.println("csvtag value : " + size3 + ", csvvalue: " + size4);     string output = null;     for(int = 0; i<= size-1; i++){         if(ctag[i].equals(csvtag[i]) == false ){         output = ("error in tag " + ctag[i]);           }         else if(cvalue[i].equals(csvvalue[i]) == false){             output = ("error in value " + cvalue[i]);           }         else{             output = ("no errors");         }     }       return output; } 

just quick @ code, see client waits 2 lines:

system.out.println(in.readline()); system.out.println(in.readline()); 

and server sends 1:

out.println(outputline); 

may problem.

i'd enclose reading part of client in try ... catch ... block, this:

try {    while (true)     {       system.out.print("input: ");       userinput = stdin.readline();       if (userinput == null) break;       out.println(userinput);        system.out.println(in.readline());       system.out.println(in.readline());        if (userinput.equals("bye."))       {           system.out.println("exit program");           break;             }     getvaluelog(parsefixmsg(userinput,userinput));  } } catch (exception e) {    e.printstacktrace(); } {     // of these lines raise exception well.     out.close();     in.close();     stdin.close();     echosocket.close();  } 

Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -