简易多人聊天室项目
跟着b站韩顺平老师做的,自己有一些小改动。为什么总是出现这个错误啊java.io.StreamCorruptedException: invalid stream header,实在检查不出来哪里出的问题。下面是源码压缩包,提取码: b8gx
package com.company.Server.model;
/**
* @Title:
* @Package
* @Description: 服务器和客户端通信线程
* @author: Yeeasy
**/
import com.company.Client.tools.TalkingViewManage;
import com.company.Client.tools.UserThreads;
import com.company.Client.tools.UserThreadsManage;
import com.company.Client.view.TalkingView;
import com.company.Shared.Message;
import java.net.*;
import java.io.*;
public class ConnectThread extends Thread {
Socket socket;
public ConnectThread(Socket socket) {
this.socket = socket;
}
public void run() {
while (true) {
try {
//接受信息
ObjectInputStream in;
ObjectOutputStream out;
in = new ObjectInputStream(socket.getInputStream());
Message msg = (Message) in.readObject();
//从usersThread中获取friend线程,转发信息
UserThreads userThread= UserThreadsManage.getUserThreads(msg.getUser());
out = new ObjectOutputStream(userThread.getSocket().getOutputStream());
out.writeObject(msg);
TalkingView talkingView= TalkingViewManage.getTalkingView(msg.getUser());
talkingView.showMessage(msg);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}