aspose file tools*
The moose likes I/O and Streams and the fly likes  I Got a Problem in ObjectInputStream while iam sending Vector 2nd Time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark " I Got a Problem in ObjectInputStream while iam sending Vector 2nd Time" Watch " I Got a Problem in ObjectInputStream while iam sending Vector 2nd Time" New topic
Author

I Got a Problem in ObjectInputStream while iam sending Vector 2nd Time

zeedan khalid
Greenhorn

Joined: Mar 18, 2004
Posts: 9
i got a problem with ObjectInputStream while iam sending Vector but in case of String it works corrects
following is the code
/////////////////////server side//////////////////////////
import java.util.*;
import java.net.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class server extends JFrame implements ActionListener
{
JButton but=new JButton("hello");
JTextField jf=new JTextField(15);
ObjectOutputStream os;
Vector v=new Vector();
public server()
{
but.addActionListener(this);
Container c=getContentPane();
c.setLayout(new FlowLayout());
c.add(but);
c.add(jf);
setSize(300,300);
show();
try
{
ServerSocket ss=new ServerSocket(9000);
Socket s=ss.accept();
ObjectInputStream is=new ObjectInputStream(s.getInputStream());
System.out.println(is.readObject());
os=new ObjectOutputStream(s.getOutputStream());
}catch(Exception ee)
{
System.out.println(ee.getMessage());
}
}
public void actionPerformed(ActionEvent e)
{
v.add(jf.getText());
try
{
os.flush();
// os.writeObject(jf.getText());/////////it works correct
os.writeObject(v);///////// it does not work correct
}catch(Exception ee)
{
System.out.println(ee.getMessage());
}
}
public static void main(String args[])
{
new server();
}
}
//////////////////////////////////clinent side code/////////////////////////////////////////////////////////////
import java.net.*;
import java.util.*;
import java.io.*;
class client
{
public client()
{
try
{
Socket s=new Socket("localhost",9000);
ObjectOutputStream os=new ObjectOutputStream(s.getOutputStream());
os.writeObject("Client Connected");
while (true)
{
ObjectInputStream is=new ObjectInputStream(s.getInputStream());
System.out.println(is.readObject());// if write String it work properly in case of vector it cuase problem
is.close();
}
}catch(Exception ee)
{
System.out.println(ee.getMessage());
}
}
public static void main(String agr[])
{
new client();
}
}
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8968
    
    9

Yea, closing a stream then trying to read from it again will tend to cause problems.


[How To Ask Questions On JavaRanch]
 
 
subject: I Got a Problem in ObjectInputStream while iam sending Vector 2nd Time