daytimeclienthelper2.java

来自「JAVA分布式程序学习的课件(全英文)」· Java 代码 · 共 29 行

JAVA
29
字号
import java.net.*;

/**
 * This class is a module which provides that application logic
 * for a Daytime Client which uses stream-mode socket for IPC.
 * @author M. L. Liu
 */

public class DaytimeClientHelper2 {
	
   public static String getTimestamp(String hostName,
      String portNum) throws Exception	{     


      String timestamp = "";      
      InetAddress serverHost = InetAddress.getByName(hostName);
      int serverPort = Integer.parseInt(portNum);
      // instantiates a stream mode socket and wait to make a 
      // connection to the server port
/**/  System.out.println("Connection request made");
      MyStreamSocket mySocket = 
      new MyStreamSocket(serverHost, serverPort); 
	   // now wait to receive the timestamp
      timestamp = mySocket.receiveMessage();
      mySocket.close( ); // disconnect is implied
      return timestamp;
   } //end 
} //end class

⌨️ 快捷键说明

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