Java-实验六
2021/9/19 20:35:07
本文主要是介绍Java-实验六,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
实验六
- 1、第一版(不成熟,第一次试探性进攻,走的java核心技术卷二的例题的样式)
1、第一版(不成熟,第一次试探性进攻,走的java核心技术卷二的例题的样式)
package Ex6.Secondquestion; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; import java.nio.charset.StandardCharsets; import java.util.Objects; import java.util.Scanner; /** * @author 15328 */ public class Main { public static void main(String[] args) throws IOException { try(ServerSocket s = new ServerSocket(8189)){ try(Socket incoming = s.accept()){ InputStream inputStream = incoming.getInputStream(); OutputStream outputStream = incoming.getOutputStream(); Scanner in = new Scanner(inputStream,"UTF-8"); PrintWriter out = new PrintWriter(outputStream,true); System.out.println("incoming.Localport: "+incoming.getLocalPort() + " incoming.Address: " + incoming.getInetAddress()); out.println("s.port: "+s.getLocalPort() + " s.Address: " + s.getInetAddress()); String str = "Verifying Server!"; out.println("Consume: " + str); System.out.println("Server: " + str); int count = 0; while(count < 3) { out.println("Input Password:"); String line = in.nextLine(); System.out.println("the test_password :" + line); if(Objects.equals(line,"195779")){ String s3 = "Registration Successful!"; System.out.println("Server: " + s3); out.println("Consumer: "+ s3); break; } else{ String s2 = "PassWord Wrong!"; System.out.println("Server: "+ s2); out.println("Consumer: " + s2 ); } count++; } if(count >= 3){ String s1 = "Illegal User!"; System.out.println("Server: " + s1); out.println("Consumer: "+ s1); incoming.close(); s.close(); } } } } }
使用telnet
这篇关于Java-实验六的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-28知识管理革命:文档软件的新玩法了解一下!
- 2024-11-28低代码应用课程:新手入门全攻略
- 2024-11-28哪些办公软件适合团队协作,且能够清晰记录每个阶段的工作进展?
- 2024-11-28全栈低代码开发课程:零基础入门到初级实战
- 2024-11-28拖动排序课程:轻松掌握课程拖动排序功能
- 2024-11-28如何高效管理数字化转型项目
- 2024-11-28SMART法则好用吗?有哪些项目管理工具辅助实现?
- 2024-11-28深度剖析:6 款办公软件如何构建设计团队项目可视化管理新生态?
- 2024-11-28HTTP缓存课程:新手入门指南
- 2024-11-28实战丨证券 HTAP 混合业务场景的难点问题应对