标题:服务器端java.net.SocketException: Connection reset异常!!
取消只看楼主
lov
Rank: 1
等 级:新手上路
帖 子:103
专家分:0
注 册:2006-12-23
 问题点数:0 回复次数:2 
服务器端java.net.SocketException: Connection reset异常!!

服务器端:
package p1;
import java.net.*;
import java.io.*;

public class s1 {


public static void main(String[] args)
{
int port =8888;
BufferedReader br;
PrintWriter pw;
ServerSocket ss;
Socket s;

try
{
ss = new ServerSocket(port);
s=ss.accept();
br=new BufferedReader(new InputStreamReader(s.getInputStream()));
pw=new PrintWriter(new BufferedWriter(new OutputStreamWriter(s.getOutputStream())),true);
System.out.println("wait.....");
while(true)
{
String str=br.readLine();
System.out.println(str);
pw.println("服务器返回:"+str);
}
}
catch(UnknownHostException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
}

}

发送端:
package p1;
import java.net.*;
import java.io.*;

import com.sun.org.apache.bcel.internal.generic.NEW;
public class c1 {

public static void main(String[] args)
{
try {
InetAddress add=InetAddress.getByName("localhost");

Socket s=new Socket(add,8888);
BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter pw=new PrintWriter(new BufferedWriter(new OutputStreamWriter(s.getOutputStream())),true);

BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
String message=reader.readLine();
pw.println(message);
pw.flush();
//String str;
String str=br.readLine();
System.out.println(str);
}
catch (UnknownHostException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}

}

}

搜索更多相关主题的帖子: java Connection 服务器 reset 
2007-01-09 09:33
lov
Rank: 1
等 级:新手上路
帖 子:103
专家分:0
注 册:2006-12-23
得分:0 
那该如何解决呢?
2007-01-09 11:02
lov
Rank: 1
等 级:新手上路
帖 子:103
专家分:0
注 册:2006-12-23
得分:0 
,谢谢!!
2007-01-09 11:36



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-115011-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.295630 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved