helloclient.java
来自「java应用开发详解」· Java 代码 · 共 38 行
JAVA
38 行
import java.io.*;
import java.net.*;
public class helloClient
{
public static void main(String[] args) throws IOException
{
Socket helloSocket = null;
PrintWriter out = null;
BufferedReader in = null;
try
{
helloSocket = new Socket ( "localhost", 1111);
out = new PrintWriter(helloSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(helloSocket.getInputStream()));
}
catch (UnknownHostException e)
{
System.err.println("Don't know about host: localhost.");
System.exit(1);
}
catch (IOException e)
{
System.err.println("Couldn't get I/O for the connection .");
System.exit(1);
}
System.out.println(in.readLine());
out.close();
in.close();
helloSocket.close();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?