java socket获取流问题 20
ObjectInputStreamoi=newObjectInputStream(socket.getInputStream());这样可以吗?我想在C/S之间传对象,可...
ObjectInputStream oi = new ObjectInputStream(socket.getInputStream());
这样可以吗?我想在C/S之间传对象,可是老是说
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.io.ObjectInputStream$PeekInputStream.read(Unknown Source)
at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source)
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.<init>(Unknown Source)
at chatroom.ClientUser$1.run(ClientUser.java:49)
问题已解决,不是连接的问题 展开
这样可以吗?我想在C/S之间传对象,可是老是说
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.io.ObjectInputStream$PeekInputStream.read(Unknown Source)
at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source)
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.<init>(Unknown Source)
at chatroom.ClientUser$1.run(ClientUser.java:49)
问题已解决,不是连接的问题 展开
展开全部
客户端代码 String ip = "localhost";
String port = pop.getProperty("8888);
Socket socket = new Socket(ip, Integer.parseInt(port));
OutputStream os = socket.getOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(os);
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(c);
oos.flush();
oos.close();
bos.close();
os.close();
socket.close();
服务器端代码
ServerSocket server = null;
Socket socket = null;
server = new ServerSocket("8888");
while (true) {
socket = server.accept();
ObjectInputStream ois = new ObjectInputStream(
new BufferedInputStream(socket.getInputStream()));
Collection<BIDR> collection = (ArrayList) ois.readObject();
//再执行相关操作
}
String port = pop.getProperty("8888);
Socket socket = new Socket(ip, Integer.parseInt(port));
OutputStream os = socket.getOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(os);
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(c);
oos.flush();
oos.close();
bos.close();
os.close();
socket.close();
服务器端代码
ServerSocket server = null;
Socket socket = null;
server = new ServerSocket("8888");
while (true) {
socket = server.accept();
ObjectInputStream ois = new ObjectInputStream(
new BufferedInputStream(socket.getInputStream()));
Collection<BIDR> collection = (ArrayList) ois.readObject();
//再执行相关操作
}
展开全部
socket client = new Socket(ip,port);
client.setSoTimeout(10000);
试试这样
client.setSoTimeout(10000);
试试这样
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Connection reset
连接重置,socket连接不成功或者中断。
连接重置,socket连接不成功或者中断。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
socket联接不成功,好好看看你的socket联接吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
fdgdfgdfg
参考资料: fgdfgdfgd
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询