循环很简单,像这样就OK:
TCPOfSend.java:
1 package com.hw.TCP0226;
2
3 import java.io.IOException;
4 import java.io.OutputStream;
5 import java.net.Socket;
6 import java.net.UnknownHostException;
7 import java.util.Scanner;
8
9 @SuppressWarnings("unused")
10 public class TCPOfSend {
11 public static void main(String[] args) throws Exception{
12 Socket s = new Socket("10.0.13.205",7892);
13
14 OutputStream output = s.getOutputStream();
15 Scanner scan = new Scanner(System.in);
16 while(true)
17 {
18 String str = scan.nextLine();
19 if(str.equals("end")) break;
20 byte[] buf = str.getBytes();
21 output.write(buf);
22 }
23 s.close();
24 }
25 }
原文:https://www.cnblogs.com/EvanTheGreat/p/14458287.html