import java.io.*; import java.net.Socket; import java.net.UnknownHostException; public class Main { public static void main(String[] args) throws IOException { //定義服務器的IP String host="10.10.10.10"; //定義服務器的端口 int Port=9095; String body=""; String jsonstr=" " + body; Socket socket = null; try { socket = new Socket(host,Port); } catch (IOException e) { e.printStackTrace(); } try { OutputStream outputStream=socket.getOutputStream(); outputStream.write(jsonstr.getBytes()); outputStream.flush(); socket.shutdownOutput(); }catch (UnknownHostException e){ e.printStackTrace(); }catch (IOException e){ e.printStackTrace(); } InputStream inputStream=socket.getInputStream(); BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(inputStream)); String result=null; while ((result=bufferedReader.readLine())!=null){ System.out.println(result); } inputStream.close(); } }