我有一个简单的客户端-服务器程序,但仍然出现连接重置异常。我对互联网的简短研究/所以我无法得出我的代码有什么问题
public class SocketServer {
public static void main (String [] args) throws Exception{
ServerSocket ss = new ServerSocket (11060);
Socket s = ss.accept();
BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
String str = br.readLine();
System.out.println("Client Data :" + str);
}
}
public class SocketClient {
public static void main (String [] args) throws Exception{
String ipAddress = "localhost" ;
int port = 11060;
Socket s = new Socket (ipAddress, port);
String str = "Hello World";
OutputStreamWriter osw = new OutputStreamWriter(s.getOutputStream());
PrintWriter pw = new PrintWriter (osw);
osw.write(str);
osw.flush();
}
}
Exception in thread "main" java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at tanvi.SocketServer.main(SocketServer.java:14)