java socket获取流问题
发布网友
发布时间:2022-04-22 09:03
我来回答
共5个回答
热心网友
时间:2023-10-06 06:12
客户端代码 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();
//再执行相关操作
}
热心网友
时间:2023-10-06 06:12
socket client = new Socket(ip,port);
client.setSoTimeout(10000);
试试这样
热心网友
时间:2023-10-06 06:12
Connection reset
连接重置,socket连接不成功或者中断。
热心网友
时间:2023-10-06 06:13
socket联接不成功,好好看看你的socket联接吧
热心网友
时间:2023-10-06 06:14
fdgdfgdfg
参考资料:fgdfgdfgd