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

📄 datagramcreator.java

📁 手机无线网络纸牌游戏源代码。非常适合学习使用
💻 JAVA
字号:
// DatagramCreator.java
//
// Copyright (c) 2000-2001 Symbian Ltd. All rights reserved

package com.symbian.devnet.whist.tokenRing;

import javax.net.datagram.*;

/**
 * Utility class for sending datagrams
 * @author Symbian Devnet
 */
class DatagramCreator
{

	/** Array of addresses that datagrams can be sent to */
	private Address[] adds;
	/** The service to use for sending datagrams */	
	private DatagramService senderService;
	
	/**
	 * Constructor
	 * @param sService 	The datagram service to use for sending datagrams
	 * @param add 		Array of addresses that can be used as destinations for 
	 * 					datagrams.
	 */
	DatagramCreator(DatagramService sService, Address[] add)
	{
		senderService = sService;
		adds = new Address[add.length];
		for (int i = 0; i < add.length; i++)
			adds[i] = add[i];			
	}

	/**
	 * Creates several datagrams to allow for multicasting 
	 * @param str 			The data to be sent
	 * @param destination 	Index in the array of addresses of the 
	 						address to send the datagram to
	 * @param idNo 			An id number for the datagram to be sent
	 */
	public void createAndSend(String str, int[] destination, int idNo)
	{	
		for (int i = 0; i < destination.length; i++)
			createAndSend(str, destination[i], idNo);	
	}	

	/**
	 * Creates a datagram and send it using the previously defined datagram 
	 * service.
	 * This version is used more frequently than the multicast version
	 * @param str 			The data to be sent
	 * @param destination 	Index of the address to send the datagram to from 
	 * 						the array of addresses supplied at construction
	 * @param idNo 			An id number for the datagram to be sent
	 */	
	public void createAndSend(String str, int destination, int idNo)
	{	
		int id = idNo;
		String st = (String.valueOf(id) + "?" + str).trim();			
		Datagram dg = new Datagram(st.getBytes(), adds[destination]);
		try
		{
			senderService.send(dg);
		}
		catch (Exception e)
		{
			System.out.println("Could not send message: " + e.getMessage());
			System.exit(0);
		}			
	}	
}	
	 

⌨️ 快捷键说明

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