⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 echoclientexample.java

📁 java 完全探索的随书源码
💻 JAVA
字号:
import java.net.*;import java.io.*;public class EchoClientExample{  public static final String HOST = "www.gatech.edu";  public static final int PORT = 7;  // Default Constructor  public EchoClientExample()  {    super();  }  public void testEcho()  {    try    {      // Get connected to an echo server somewhere, they are usually on      // port 7 of a well known server      Socket socket = new Socket( HOST, PORT );      // Create a reader and stream for reading the data from the echo server      BufferedReader input = new BufferedReader( new InputStreamReader(socket.getInputStream()));      // Create a writer and stream for writing to the echo server      PrintWriter output = new PrintWriter( socket.getOutputStream(), true);      // Send some text to the echo server      System.out.println( "Sending Hello to the echo server" );      output.println( "Hello" );      // Get the message from the echo server      System.out.println( input.readLine() + " from the echo server at " + HOST );      // Close the socket      socket.close();    }    catch(UnknownHostException ex)    {      System.err.println("Unknown host: " + ex);      System.exit(1);    }    catch(IOException excpt)    {      System.err.println("Failed I/O: " + excpt);      System.exit(1);    }  }  public static void main(String[] args)  {    EchoClientExample example = new EchoClientExample();    example.testEcho();  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -