2012-02-18 132 views
1

我不知道为什么,但突然我在发送和接收通过TCP套接字列表面临的问题发送列表<>对象,最初我成功地这样做。这里是我的转让代码: 发件人:问题通过套接字

List<String> A = ....; 
ObjectOutputStream out = new ObjectOutputStream(soc.getOutputStream()); 
System.out.println("Wrinting the answers"); 
out.writeObject(A); 
System.out.println("Wrote the answers, now reading the flag"); 

我正确地得到SOP,但是reciever进入等待状态:

ObjectInputStream in = new ObjectInputStream(soc.getInputStream());    
ls = (List<String>)in.readObject(); 
System.out.println("Recieved the list of results"); 

在这里,我没有得到的SOP和接收器继续处于等待状态。 补充:我是成功的在先前转化中的名单,但后来我在这里和那里,现在做了一些改变不知道是什么问题。其实,我打算转移另一个列表<>过,但我会努力,只有当我得到解决的第一个问题!谢谢您的回答..

+1

尝试转换列表对象对象类型和发送 – Prabhavith 2012-02-18 13:42:17

+2

名单*是*的对象。没有什么可转换的。 – 2012-02-18 13:50:07

+1

你有SOP工作正常,因为你写的数据缓冲。一旦完成了对象的编写,你应该调用'out.flush()'。 – SuperSaiyan 2012-02-18 14:01:48

回答

2

试试这个:

ObjectOutputStream out = new ObjectOutputStream(soc.getOutputStream()); 
System.out.println("Wrinting the answers"); 
out.writeObject(A); 
out.flush(); // flush the stream! 
System.out.println("Wrote the answers, now reading the flag"); 
+0

我曾试图以红晕,还没有我得到了相同的结果。 – Purushottam 2012-02-18 15:19:53