我设定无效登录最大为3次,为什么无效登录2次客户端就报错停止了,弄的几个好久都不行(一晚上就敲了两个小程序还都不行,郁闷),求大侠帮忙指点一下!谢谢!
下面是代码:
import java.io.*;
import java.net.*;
class LogClient
{
public static void main(String[] args)throws Exception
{
Socket s=new Socket("192.167.12.98",10007);
BufferedReader bufr=
new BufferedReader(new InputStreamReader(System.in));
PrintWriter out=new PrintWriter(s.getOutputStream(),true);
BufferedReader bufrin=
new BufferedReader(new InputStreamReader(s.getInputStream()));
for(int x=0;x<3;x++)
{
String line=bufr.readLine();
if(line==null)
break;
out.println(line);
String info=bufrin.readLine();
System.out.println(info);
if(info.contains("here"))
break;
}
s.close();
bufr.close();
}
}
class LogThread implements Runnable
{
private Socket s;
LogThread(Socket s)
{
this.s=s;
}
public void run()
{
String ip=s.getInetAddress().getHostAddress();
System.out.println(ip+" ..contect..");
try
{
for(int x=0;x<4;x++)
{
BufferedReader bufrin
=new BufferedReader(new InputStreamReader(s.getInputStream()));
String name=bufrin.readLine();
if(name==null)
break;
BufferedReader bufr
=new BufferedReader(new FileReader("D:\\1.txt"));
PrintWriter out=new PrintWriter(s.getOutputStream(),true);
String line=null;
boolean flag=false;
while((line=bufr.readLine())!=null)
{
if(line.equals(name))
{
flag=true;
break;
}
}
if(flag)
{
System.out.println(ip+"已登录");
out.println("wecome to here");
break;
}
else
{
System.out.println(ip+"尝试登录");
out.println("账户不存在");
}
s.close();
}
}
catch (Exception e)
{
throw new RuntimeException("校验失败");
}
}
}
class LogServer
{
public static void main(String[] args)throws Exception
{
ServerSocket ss=new ServerSocket(10007);
while(true)
{
Socket s=ss.accept();
new Thread(new LogThread(s)).start();
}
}
} |
|