🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #18815

Re: Socket problems...

#18815
From: AcidSteve
Date: Sat, 18 Apr 1998 00:00
101 lines
3668 bytes
Asessandro, I came across familiar errors occasionally. Don't know where
the problem exactly lies, but try to change your program in the
following way:
  -initialize in/out streams in the constructor   
(MultiFileThreadCopier)
  -initialize them together (in one try/catch block, one after another)

The way I see your program should be changed, see below.

Think the error messages would not appear any more.

PS: Since u studing the transfering objects through net, could u    
    possibly advice something for resolving my "ObjectInputStream    
problem" (quite recent message)

> class MultiFileThreadCopier extends Thread {
>   Socket socket ;
>   Debug Debug1 = null;
>   MultiFileThreadCopier(Socket socket,int counter)
>   {
>     super("FileCopy"+ new Integer(counter).toString());
>     this.socket = socket;
>!!!      ois = new ObjectInputStream(socket.getInputStream());
>!!!      out = new ObjectOutputStream(socket.getOutputStream());
   }
> 
>   public void run()
>   {
>////     ObjectInputStream ois = null;
>////     ObjectOutputStream out = null;
>     try
>     {
>       Debug1 = new Debug(System.err);
>       Debug1.setShowMessageOutPut(true);
>       Hashtable Hashret = new Hashtable();
> 
>////      ois = new ObjectInputStream(socket.getInputStream());
>       Hashtable t = (Hashtable)ois.readObject();
>       ois.close();
>       Hashret.put("return","true");
>       System.err.println(Hashret);
>////       out = new ObjectOutputStream(socket.getOutputStream()); << this is
> the line 34 where exception occurs
>       out.writeObject(Hashret);
>       out.close();
> 
>     } catch (Exception ex2)
>     {
>       ex2.printStackTrace();
>     } finally {
>       try {
>         socket.close();
>       } catch (Exception ex)
>       {
>         ex.printStackTrace();
>       }
>     }
>   }
> 
> }
> 
> public class MultiFileClient {
> 
>   public static void main(String[] args) {
>     Socket kksocket = null;
>     ObjectInputStream ois = null;
>     ObjectOutputStream ous = null;
>     try {
> 
>       kksocket = new Socket("localhost",4444);
>       Hashtable t = new Hashtable();
>       t.put("sessionid","");
>       t.put("command","GET DIR FILES");
>       ous = new ObjectOutputStream(kksocket.getOutputStream());
>       ous.writeObject(t);
>       ous.close();
>       t.clear();
>       ois = new ObjectInputStream(kksocket.getInputStream());
>       t = (Hashtable)ois.readObject();
>       ois.close();
> 
>       Enumeration enum2 = t.elements();
>       for (Enumeration enum = t.keys() ; enum.hasMoreElements() ;) {
>         String FileName = (String) enum.nextElement();
>         String SFileSizeAndCRC = (String) enum2.nextElement();
>         System.out.println(FileName+ " "+ SFileSizeAndCRC);
>       }
>     } catch (UnknownHostException ex1)
>     {
>       System.err.println(ex1.toString());
>     } catch (IOException ex2)
>     {
>       System.err.println(ex2.toString());
>     } catch (Exception ex3)
>     {
>       System.err.println(ex3.toString());
>     }
> 
>   }
> }
Technical Details
Message-ID: <3538A26F.E5ED344E@hempseed.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <35361A21.C500C6D1@tin.it>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,f8d273ae612f1fa5
X-Google-Attributes: gidf74b3,public
From: AcidSteve <acidsteve@hempseed.com>
Subject: Re: Socket problems...
Date: 1998/04/18
Message-ID: <3538A26F.E5ED344E@hempseed.com>
X-Deja-AN: 345349524
Content-Transfer-Encoding: 7bit
References: <35361A21.C500C6D1@tin.it>
Content-Type: text/plain; charset=koi8-r
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language