【TCP传输数据-键盘录入】
生活随笔
收集整理的這篇文章主要介紹了
【TCP传输数据-键盘录入】
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
package com.yjf.esupplier.common.test;import java.io.*;
import java.net.Socket;/*** @author shusheng* @description TCP 傳輸數(shù)據(jù):鍵盤錄入* @Email shusheng@yiji.com* @date 2019/1/15 22:57*/
public class ClientDemo1 {public static void main(String[] args) throws IOException {// 創(chuàng)建發(fā)送端的Socket對象Socket socket = new Socket("localhost", 8888);BufferedReader br = new BufferedReader(new InputStreamReader(System.in));BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));String line = null;while ((line = br.readLine()) != null) {// 鍵盤錄入數(shù)據(jù)要自定義結束標記if ("886".equals(line)) {break;}bw.write(line);bw.newLine();bw.flush();}socket.close();}} package com.yjf.esupplier.common.test;import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;/*** @author shusheng* @description TCP 傳輸數(shù)據(jù):鍵盤錄入* @Email shusheng@yiji.com* @date 2019/1/16 21:11*/
public class ServerDemo1 {public static void main(String[] args) throws IOException {// 創(chuàng)建接收端的 Socket 對象ServerSocket ss = new ServerSocket(8888);Socket s = ss.accept();BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));String line = null;while((line=br.readLine())!=null){System.out.println(line);}s.close();}}
?
轉載于:https://www.cnblogs.com/zuixinxian/p/11275398.html
總結
以上是生活随笔為你收集整理的【TCP传输数据-键盘录入】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 随便贴两个漏洞,如 Apache JSe
- 下一篇: 04