Geo*_*ips 0 java sockets network-programming stream
我目前正在尝试让我的服务器与客户端建立连接.我为每个连接创建了一个线程,但服务器当前没有创建输入流.我通过打印数字来测试这个,但只有1和2打印出来.我确定这只是一个我遗漏的小问题.
public class ObjectHandler implements Runnable{
Socket sock;
ObjectInputStream ois;
ObjectOutputStream oops;
InputStream is;
public ObjectHandler(Socket clientSocket) throws IOException {
System.out.println("1");
sock = clientSocket;
is = sock.getInputStream();
System.out.println("2");
ois = new ObjectInputStream(new BufferedInputStream(is));
System.out.println("3");
OutputStream os = sock.getOutputStream();
oops = new ObjectOutputStream(new BufferedOutputStream(os));
outputSockets.add(oops);
}
Run Code Online (Sandbox Code Playgroud)
我现在已经删除了抛出IOException并用try catch包围了读者.客户端崩溃后,它现在打印此错误:
at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2280)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2749)
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:779)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:279)
at ThreadPool$ObjectHandler.<init>(ThreadPool.java:95)
at ThreadPool.addThread(ThreadPool.java:31)
at ObjectServerTest.go(ObjectServerTest.java:93)
at ObjectServerTest.main(ObjectServerTest.java:124)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10915 次 |
| 最近记录: |