daytimeclient.java
来自「Java网络编程与分布式计算, 主要分析java网络各方面的编程, 提供许多实用」· Java 代码 · 共 46 行
JAVA
46 行
import java.net.*;
import java.io.*;
// Chapter 6, Listing 1
public class DaytimeClient
{
public static final int SERVICE_PORT = 13;
public static void main(String args[])
{
// Check for hostname parameter
if (args.length != 1)
{
System.out.println ("Syntax - DaytimeClient host");
return;
}
// Get the hostname of server
String hostname = args[0];
try
{
// Get a socket to the daytime service
Socket daytime = new Socket (hostname, SERVICE_PORT);
System.out.println ("Connection established");
// Set the socket option just in case server stalls
daytime.setSoTimeout ( 2000 );
// Read from the server
BufferedReader reader = new BufferedReader (
new InputStreamReader(daytime.getInputStream()
));
System.out.println ("Results : " + reader.readLine());
// Close the connection
daytime.close();
}
catch (IOException ioe)
{
System.err.println ("Error " + ioe);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?