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

📄 daytimeclient.java

📁 Java网络编程与分布式计算, 主要分析java网络各方面的编程, 提供许多实用安全
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -