创建端口
Posted 丿随缘
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了创建端口相关的知识,希望对你有一定的参考价值。
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(); }
以上是关于创建端口的主要内容,如果未能解决你的问题,请参考以下文章