xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Octav Chipara <ochip...@cse.unl.edu>
Subject Java Help
Date Wed, 10 May 2000 17:44:25 GMT


Hi,

I hope that among you there are some Java genius able to help me. I am
trying to make a client and a have big problem in Java not waiting for the
for the server to end its message. Do you have any idea how can I get
around this problem. Any ideas and suggestions are more then welcomed. 

Thanks,
Octav


PS: My code is:

import java.net.*;
import java.io.*;

public class Client1_0 {

  //Main method
  public static void main(String[] args) throws IOException
  {
  Socket NewSocket=null;
  PrintWriter out=null;
  BufferedInputStream in=null;

  //String HostName="cse-mfayad2.unl.edu";
  String HostName="cse.unl.edu";
  DataInputStream stdin= new DataInputStream(System.in);

  try
    {
    System.out.println("Starting to tests...");
    NewSocket=new Socket(HostName,21);
    out= new PrintWriter(NewSocket.getOutputStream(),true);
    in = new BufferedInputStream(NewSocket.getInputStream(), 1000);
    } catch (UnknownHostException e){
    System.err.println("Unknown host ("+HostName+")");
    System.exit(-1);
    } catch (IOException e) {
    System.err.println("Could not get IO access to "+HostName);
    System.exit(-1);
    };
    System.out.println("Connection to "+HostName+" established");


    byte i;
    String UI;
    int j;
    int size=0;

    while (size==0) size=in.available();
    for (j=0;j<size;j++) System.out.print((char)in.read());

    while (true)
    {
    UI=stdin.readLine();
    out.println(UI);
    try
      {
      in.wait();
      size=0;
      while (size==0) size=in.available();
      size=in.available();
      System.out.println("****"+size);
      for (j=0;j<size;j++) System.out.print((char)in.read());
      } catch (
      } catch (EOFException e) {
      System.err.println("OK");
      } catch (IOException e) {
      System.err.println("OK");
      };
    };
   };
};


Mime
View raw message