简单的Socket传输

public class server {
    public static void main(String[] args) throws Exception {
        ServerSocket ss = new ServerSocket(8092);
        Socket s = ss.accept();
        BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
        System.out.println(br.readLine());
        br.close();
        
    }
}

 

public class client {
    public static void main(String[] args) throws Exception {
        Scanner sca = new Scanner(System.in);
        Socket s = new Socket("localhost", 8092);
        PrintWriter pw = new PrintWriter(s.getOutputStream());
        pw.write(sca.next());
        pw.flush();
        pw.close();
    }
}

posted @ 2018-09-10 22:20  萧愬夜  阅读(120)  评论(0)    收藏  举报