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

📄 senddatagram.java

📁 datagram application(basee on server-client) where the server sends the current time through a data
💻 JAVA
字号:
/* SendDatagram.java 
*
*  Author: Terry Ridge
*
*  Permission to use, copy, modify, and distribute
*  this software for NON_COMMERCIAL purposes and without
*  fee is hereby granted provided that this copyright notice
*  appears in all copies.
*
*  The creators of this software make no representations or
*  warranties about the suitability of the software, either
*  express or implied.  The creators shall not be liable for
*  any damages suffered by licensee as a result of using,
*  modifying or distributing this software or its derivatives.
*/

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

public class SendDatagram
   {

   public static void main(String[] args)
      {
      String message = "This is the message we are sending";
      int port=2222;

     /* if (args.length != 2)
         {
         System.out.println("Usage: java SendDatagram <host name> <port>");
         System.exit(0);
         }

      port = Integer.parseInt(args[1]);
*/
      try
         {
         InetAddress address = InetAddress.getByName("127.0.0.1");

         byte buffer[] = new byte[message.length()];
         message.getBytes(0, message.length(), buffer, 0);

         DatagramPacket sendPacket =
            new DatagramPacket(buffer, buffer.length, address, port);

         DatagramSocket socket = new DatagramSocket();
		// System.out.println("The message was sended from host: "+address);
		 System.out.println("The message was sended from port: "+port);
			
         socket.send(sendPacket);
         }
      catch (IOException e)
         {
         System.err.println("Error sending datagram: " + e);
         }
      }
   }


⌨️ 快捷键说明

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