- ServerSocket ser=new ServerSocket(47656);
- while(true){
- Socket s=ser.accept();
- new Thread(new Sert(s)).start();
- }
- }
- }
- class Sert implements Runnable{
- private Socket s;
- Sert(Socket s){
- this.s=s;
- }
- public void run() {
- String ip=s.getInetAddress().getHostName();
- System.out.println(ip);
- try{
- for(int x=0;x<10;x++){
- BufferedReader bufr=new BufferedReader(new InputStreamReader(s.getInputStream()));
- String name=bufr.readLine();
- if(name==null){
- break;
- }
- BufferedReader bufn=new BufferedReader(new FileReader("use.txt"));
- PrintWriter out=new PrintWriter(s.getOutputStream());
- String lin=null;
- boolean fa=false;
- while((lin=bufn.readLine())!=null){
- if(lin.equals(name)){
- fa=true;
- break;
- }
- }
- if(fa){
- System.out.println(name+"yidognlu");
- break;
- }
- else{
- System.out.println("no access"+name);
- out.println("bucunz"+name);
-
- }
- }
- s.close();
- }
- catch(Exception e){
- throw new RuntimeException("shibai"+ip);
- }
- }
- }
复制代码
这个是 服务端的
- Socket s=new Socket("192.168.0.100",47656);
- BufferedReader bufr=new BufferedReader(new InputStreamReader(System.in));
- PrintWriter pw=new PrintWriter(s.getOutputStream(),true);
- BufferedReader bufi=new BufferedReader(new InputStreamReader(s.getInputStream()));
- for(int x=0;x<10;x++){
- String line=bufr.readLine();
- if(line==null){
- break;
- }
- pw.println(line);
- String inf=bufi.readLine();
- System.out.println(inf);
- if(inf.contains("yingdenglu")){
-
- break;
- }
-
- }
- bufr.close();
- s.close();
复制代码
这个是客户端
哪位大神 帮忙看看 为什么 输入了好几个 但是只有一个反馈呢
|
|