首页 > 代码库 > 创建端口
创建端口
import java.io.BufferedReader; import java.io.*; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.*; import java.net.Socket; import java.net.UnknownHostException; import java.util.*; public class Client { private static PrintWriter pw=null; private static BufferedReader br=null; private static Socket s; private static ServerSocket ss; static Scanner scanner=new Scanner(System.in); /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub try { Socket s=new Socket(InetAddress.getLocalHost(),5500); pw=new PrintWriter(new OutputStreamWriter(s.getOutputStream())); br=new BufferedReader(new InputStreamReader(s.getInputStream())); while(true){ System.out.println("Client端请输入:"); String str = scanner.next(); pw.println(str); pw.flush(); String string=br.readLine(); System.out.println("Client读到:"+string); if(str.equals("exit")){ break; } } }catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } try { br.close(); pw.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }
创建端口
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。