网络画板,传送一个“储存点的点向量”遇到问题

Programming_SLK 2012-12-01 03:24:13
客户端链接服务器代码:
 

private void connectToServer() {
try {
// Create a socket to connect to the server
Socket socket=null;
if (isStandAlone)
socket = new Socket(IP, port);
else
socket = new Socket(getCodeBase().getHost(), port);
toServer = new ObjectOutputStream(socket.getOutputStream());
}
catch (Exception ex) {
System.err.println(ex);
}
}


客户端发送点向量代码:

private void sendPointVector(Vector<Point> v ) throws IOException {
toServer.writeObject(v);
System.out.println("传点向量中。。。。");
}



服务器端连接客户端代码:
private void connectToClient() {
try {
ServerSocket S_socket=null;
S_socket = new ServerSocket(port);
Socket socket = S_socket.accept();
System.out.println("客户端到服务器的链接已建立");
fromServer = new ObjectInputStream(socket.getInputStream());
System.out.println("fromeServer输入流已经建立");
}
catch (Exception ex) {
System.err.println(ex);
}
}


服务器端接收点向量方法:
public void getClientPointVector() throws IOException {
System.out.println("正在接受客户端发来的数据。。。。");
Vector<Point> Vec = new Vector<Point>();//点信息向量组
try {
if(VectorClass.isInstance(fromServer.readObject()))
{
Vector<Point> readObject = (Vector<Point>)fromServer.readObject();
Vec=readObject;
paintInfo=Vec;
System.out.println("收到了"+paintInfo.size()+"个点");
repaint();

}
else
System.out.println("接收的数据格式错误!");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


Point是我自己写的,implements了序列化接口
...全文
207 5 打赏 收藏 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lcf 2013-09-10
  • 打赏
  • 举报
回复
服务器端每次都是重新赋值了一个List<Vector>
f2081 2013-09-10
  • 打赏
  • 举报
回复
好深奥啊。学习中。。。。。。。
Programming_SLK 2012-12-02
  • 打赏
  • 举报
回复
求助啊...求助
Programming_SLK 2012-12-01
  • 打赏
  • 举报
回复
我传Point,一个一个的Point传输的时候是可以的。
Programming_SLK 2012-12-01
  • 打赏
  • 举报
回复
问题就是我客户端传输的时候,可以在console里看到我的paintInfo(存点的向量)的size不断在变化。 但是在服务器端,Vec始终没有变化

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧