我正在尝试执行一个简单的客户端/服务器程序。但是每当我尝试执行时,我都会收到“java.net.SocketException:Connection reset”。为什么会发生此异常?对我有什么建议吗?
这是代码
SocServer.java
public static void main(String[] args) throws Exception
{
System.out.println("Server is started");
ServerSocket ss = new ServerSocket(8886);
System.out.println("Server is waiting for client request");
Socket s = ss.accept();
System.out.println("Client Connected");
BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
String str = br.readLine();
System.out.println("Client Data" + str);
}
SocketClient.java
public static void main(String[] args) throws Exception
{
String ip = "localhost";
int port = 8886;
Socket s = new Socket(ip,port);
String str = "Noman";
OutputStreamWriter os = new OutputStreamWriter(s.getOutputStream());
PrintWriter out = new PrintWriter(os);
os.write(str);
os.flush();
}
答案 0 :(得分:0)
可能的原因