创建了服务器端跟客户端,运行之后报错:Socket : Connection reset
服务端代码为:
public class JobWork05 {
public static void main(String[] args) {
try (ServerSocket serverSocket = new ServerSocket(8888);
) {
Socket socket = ();
OutputStream os = ();
(“你好,服务端接收到了”.getBytes());
InputStream is = ();
BufferedReader bf = new BufferedReader(new InputStreamReader(is));
int len=0;
while ((len = ()) != -1){
((char)len);
}
();
} catch (IOException e) {
();
}
}
}
客户端的代码为:
public class JobWork06 {
public static void main(String[] args) {
try(
Socket socket = new Socket(“127.0.0.1”,8888);
) {
int len;
byte[] bytes = new byte[1024];
OutputStream os = ();
(“hello.服务器,我是客户端”.getBytes());
();
InputStream is = ();
while ((len = (bytes))!= -1){
(new String(bytes,0,len));
}
}catch (IOException e){
();
}
}
}
运行之后报错,经查阅问题描述如下:
1,如果一端的Socket被关闭(或主动关闭,或因为异常退出而 引起的关闭),另一端仍发送数据,发送的第一个数据包引发该异常(Connect reset by peer)。
相关文章
- Socket : Connection reset的解决方案
- 前端页面报net::ERR_CONNECTION_RESET错误的原因
- Lost connection to server at handshake: reading initial communication packet 异常的解决方案
- Connection reset by peer的常见原因及解决办法
- Socket : Connection reset的解决方案
- 分析connection reset by peer, socket write error错误原因
- 上传文件小的oK,大一点的传不了,显示 (failed) net::ERR_CONNECTION_RESET
- 浏览器报net:err::connection--reset,链接重置的异常解决
- Connection reset by peer的常见原因及解决办法
- connection reset by peer问题总结及解决方案