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

📄 multitimeclient.java

📁 java3D game engine design of the source [three-dimensionalvirtualrealitynetworkprogram] - "virtual
💻 JAVA
字号:

// MultiTimeClient.java
// Andrew Davison, June 2003, dandrew@ratree.psu.ac.th

/* Listen for packets coming from the specified multicast group.
   The packets should hold the current date.

   The client runs forever, so doesn't use leaveGroup().
*/

import java.net.*;
import java.io.*;

public class MultiTimeClient
{
  private static final String MHOST = "228.5.6.7";
  private static final int PORT = 6789;

  public static void main(String args[]) throws IOException
  {
     InetAddress address = InetAddress.getByName(MHOST);        
     MulticastSocket msock = new MulticastSocket(PORT);
     msock.joinGroup(address);

     byte[] buf = new byte[1024];
     DatagramPacket packet = new DatagramPacket(buf, buf.length);
     String dateStr;
     while(true){                                
       // buf = new byte[1024];
       // packet = new DatagramPacket(buf, buf.length);
       msock.receive(packet); 
       dateStr = new String( packet.getData() ).trim();
       System.out.println(packet.getAddress() + " : " + dateStr);
     }
   }  // end of main()
         
}  // end of MultiTimeClient class

⌨️ 快捷键说明

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