亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? tokenring.java

?? 手機無線網絡紙牌游戲源代碼。非常適合學習使用
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
// TokenRing.java
//
// Copyright (c) 2000-2001 Symbian Ltd. All rights reserved

package com.symbian.devnet.whist.tokenRing;

import java.io.*;
import javax.net.datagram.*;
import java.util.*;

/**
 * A class implementing a token ring engine.
 * Implements DatagramListener
 * @see com.symbian.devnet.whist.tokenRing.DatagramListener
 * @author Symbian Devnet
 */
public class TokenRing implements DatagramListener
{
	/** 
	 * The default port for receiving datagrams on.  This is used when all engines 
	 * are running on different machines.
	 */
	private static final int RECEIVE_PORT = 9999;
	/** The variable used to determine when UDP datagrams are required. */	
	private static final int UDP = 0;
	/** The variable used to determine when WDPSMS datagrams are required. */		
	private static final int WDPSMS = 1;
	/** The number of Engines participating in the ring*/	
	private static final int NO_OF_ENGINES = 4;
	/** A temporary UDP address used to determine the IP number of the machine. */	
	private final static String DUMMY_ADDRESS_UDP = "udp://+1234567890:9999";
	/** A temporary WDPSMS address used to determine the IP number of the machine. */
	private final static String DUMMY_ADDRESS_WDPSMS = "wdpsms://+123456789:9999"; 	
	/** The instance of a DatagramEvent. */	
	private DatagramEvent dgEvent;	
	/** A string representing the address for sending and receiving for the device. */	
	private String commsAddress;
	/** A string representing the port number. */	
	private String port;
	/** An instance of a Ring. */	
	private Ring rg;
	/** An instance of a Receiver. */
	private Receiver receive;
	/** An instance of a DatagramService. */
	private DatagramService senderService;	
	/** An instance of a DatagramCreator. */	
	private DatagramCreator dgCreator;
	/** Indicates the address to which the message should be sent. */
	private int nextAddress = 1;	
	/** The protocol to be used for sending datagrams, either UDP or WDPSMS. */ 
	private int protocol;
	/** An array of the names of the players */	
	private String names[];
	/** An instance of a DatagramService. */
	private DatagramService dummy;	
	/** 
	 * An array of the addresses of the individual Token Ring Receivers 
	 * represented as Strings. 
	 * @see com.symbian.devnet.whist.tokenRing.Receiver Receiver
	 */	
	private String adds[];
	/**
	 * The address of the local machine (localhost). This will be used as the 
	 * Address for the Sender and Receiver. 
	 */
	private Address myAddress;
	/** The identification number of the last datagram message sent. */	
	private int idNo;
	/** 
	 * The position of the player in the ring, for example playerNo = 3 indicates 
	 * that this is the third player. 
	 */
	private int playerNo;
	/** 
	 * The array of data received from the datagram.  The maximum size for this is 
	 * 160, which is the maximum size of an SMS message.
	 */ 	
	private byte[] dataReceived = new byte[160];
	/** 
	 * Used to copy the data in {@link com.symbian.devnet.whist.tokenRing.TokenRing#dataReceived dataReceived}
	 * to ensure that data from a new datagram will not overwrite 
	 * the data from the original datagram until it has been processed and discarded.
 	 */ 	
	private byte[] data = new byte[160];
	/** Vector of listeners for GameEvents */
	private Vector listeners = new Vector();	

	/**
	 * Constructor to initiate a token ring Engine which will wait until a datagram 
	 * containing the information required to create the 
	 * {@link com.symbian.devnet.whist.tokenRing.Ring#Ring(String[], String[]) Ring}
	 * is received.
	 * The {@link #createSender() createSender} method creates an instance of a 
	 * an object through 
	 * which datagrams can be sent.  The {@link #setupEngine(String) setupEngine} 
	 * method initialises the objects which are generic to both constructors.
	 * @param pProtocol 	the protocol to be used, either UDP or WDPSMS.
	 * @param rPort			the port number for the Receiver.
	 * @param sport			the port number for the Sender.
	 */
	public TokenRing()
	{
		protocol = UDP;
		String[] ports = { "1010", "1011", "1012", "1013" };
		port = ports[0];
		int count = 0;
		boolean b = setupEngine(port);	
		while (!b && (count < 3))
		{
			port = ports[++count];
			b = setupEngine(port);
		}					
	}	
	
	/**
	 *	Configures the generic parts of the Engine.  This is used by both 
	 * constructors and initialises common variables.
	 * This method creates a String comprising of the protocol method (UDP or 
	 * WDPSMS), the IP number of the device (Node), and the port number designated 
	 * for receiving datagrams.  If an Exception is not thrown, a new 
	 * {@link com.symbian.devnet.whist.tokenRing.Receiver Receiver}, called 
	 * receive, is created.  The Receiver object is then added to the 
	 * {@link com.symbian.devnet.whist.tokenRing.DatagramListener DatagramListener} 
	 * vector and the {@link com.symbian.devnet.whist.tokenRing.Receiver#listen listen}
	 * method is called on receive.
	 * <P>
	 * The Engine now listens for incoming datagrams.
	 * @param port 	the port number for the Receiver.
	 */
	private boolean setupEngine(String port)
	{
		boolean b = true;
		if (protocol == UDP)
			commsAddress = "udp://" + getNodeIPNo() + ":" + port;	
		else
			commsAddress = "wdpsms://" + getNodeIPNo() + ":" + port;
			
		try
		{
			myAddress = DatagramService.parseAddress(commsAddress);
		}
		catch(Exception ex)
		{
		}
		
		DatagramService dgService;
		
		try
		{
			dgService = DatagramService.getServerService(myAddress);
			
			receive = new Receiver(dgService, myAddress);
			receive.addDatagramListener(this);
			receive.listen();					
		}
		catch(Exception e)
		{
			b = false;
		}	
		
		return b;
	}

	/**
	 * This calls the 
	 * {@link com.symbian.devnet.whist.tokenRing.TokenRing#getidNo() getidNo}
	 *  method to extract the identification number from the received data 
	 * and the performs different actions depending on the value of the current 
	 * identification number and the identification number of the received message.
	 * <P>
	 * If the current identification number 
	 * ({@link com.symbian.devnet.whist.tokenRing.TokenRing#idNo idNo}
	 * ) is zero, the 
	 * {@link com.symbian.devnet.whist.tokenRing.Ring Ring}
	 * object has not been instantiated.  The
	 *  {@link com.symbian.devnet.whist.tokenRing.TokenRing#idNo idNo} is set to the 
	 * identification number of the current message and the data from the datagram 
	 * (without the identification number) is extracted into a char array. This is 
	 * then passed to the Ring constructor to initialise a Ring.  
	 * <P>
	 * Another comparison is made to determine if this is the last device in the 
	 * token ring to be initialised.  If this is not the last device, the character 
	 * array is parsed as a String and the 
	 * {@link com.symbian.devnet.whist.tokenRing.DatagramCreator#createAndSend(String, int, int) createAndSend}
	 * method is called 
	 * to pass the setup details onto the next device in the ring.  If this is the 
	 * last device to be setup, a datagram is sent to the first machine in 
	 * the ring (the initiator). 
	 * <P>
	 * If the identification number from the datagram is less than or equal to the 
	 * current identification number, the datagram is either a duplicate or old 
	 * and can be ignored.
	 * <P>
	 * If the current identification is not equal to zero and the datagram is new, 
	 * the data contained within it will be passed into the package above for 
	 * processing
	 */	
	private void processMessage()
	{	
		int id = getidNo();	
		if (idNo == 0) 
		{			
			// A message containing the information required to set 
			// up the ring has been received.
			idNo = id;
			playerNo = idNo + 1;	
			char[] c = getData(data);
			rg = new Ring(c);
			createSender();
			setNextAddress();			
			if (playerNo < NO_OF_ENGINES) 
			{		
				// Need to send setup message onto one or more other
				// machines
				String s = new String(c).trim();		
				dgCreator.createAndSend(s, nextAddress, ++idNo);
			}
			else 			
			{
				// This is the last player in the game (all others have 
				// received the setup datagram.
				ReceivedTurnEvent ge = new ReceivedTurnEvent(this, c);	
				dgCreator.createAndSend("X", nextAddress, ++idNo);
			}
		}
		else if (id <= idNo)
		{		
			// An old message has been sent and should be ignored.
			System.out.println("Received old message - id: " + id);
		} 
		else
		{		
			// The datagram contains data for the Game.
			idNo = id;
			char[] c = getData(data);
			ReceivedTurnEvent ge = new ReceivedTurnEvent(this, c);				
			processReceivedTurn(ge);	
		}		
	}
	
	/** 
	 * Sets nextAddress, the variable which indicates which address in the array of 
	 * addresses is to be used for the datagram which is about to be sent.
	 */	
	private void setNextAddress()
	{
		if (playerNo == 4)
			nextAddress = 0;
		else
			nextAddress = playerNo;
	}	
	
	/**
	 * Extracts the data from the byte array and strips off the identification 
	 * number.
	 * @return the data from the message as a character array.
	 */	
	private char[] getData(byte[] buf)
	{
		char cha = '?';
		int i = 0;
		while ((char)data[i] != cha)
			i++;
		i++;
		char[] c = new char[data.length - i];
		for (int j = 0; j < c.length; j++)
			c[j] = (char)data[j + i];
		return c;
	}	

	/** 
	 * Extracts the identification number from the byte array obtained from a 
	 * datagram.
	 * @return the identification number of the datagram.
	 */
	private int getidNo()
	{
		char cha = '?';
		char[] ch = new char[6];
		int i = 0;
		while ((char)data[i] != cha)
			ch[i] = (char)data[i++];
		String num = new String(ch);
		String n2 = new String(num.trim());
		Integer inte = Integer.valueOf(n2);
		int id = inte.intValue();
		return id;
	}

	/**
	 * Creates a DatagramCreator object that can be used to send datagrams to the 
	 * nodes in the ring
	 */	
	private void createSender()
	{		

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美成人三级在线| 一区二区不卡在线播放| 国产精品久久久久影院| 无码av中文一区二区三区桃花岛| 国产成人av影院| 91精品国产91久久久久久一区二区| 欧美激情在线看| 久久99久国产精品黄毛片色诱| 色视频成人在线观看免| 国产亚洲成aⅴ人片在线观看| 午夜av一区二区| 一本一本久久a久久精品综合麻豆| 精品免费日韩av| 日韩高清欧美激情| 在线看日韩精品电影| 亚洲欧美怡红院| 粉嫩av一区二区三区| 精品欧美黑人一区二区三区| 午夜精品aaa| 欧美日韩不卡一区二区| 亚洲精品国产成人久久av盗摄| 国产成人精品免费| 国产偷国产偷亚洲高清人白洁| 久久av老司机精品网站导航| 91精品综合久久久久久| 午夜精品久久久| 777奇米成人网| 日本在线不卡视频| 5858s免费视频成人| 日韩在线播放一区二区| 欧美日韩视频专区在线播放| 一区二区三区91| 欧美三级在线视频| 亚洲综合激情网| 欧美日韩成人综合天天影院| 天天影视色香欲综合网老头| 欧美精品第1页| 另类小说欧美激情| 精品国产成人在线影院| 国产一二精品视频| 中文字幕精品一区二区精品绿巨人 | 自拍偷拍欧美精品| av一区二区三区在线| 最新日韩av在线| 色婷婷亚洲一区二区三区| 中文字幕制服丝袜成人av| 99精品偷自拍| 亚洲永久精品大片| 91精品国产乱码| 国产酒店精品激情| 国产精品国产三级国产普通话三级| 成人在线视频一区二区| 亚洲免费色视频| 欧美一区二区免费视频| 国产最新精品精品你懂的| 亚洲国产精品精华液ab| 99精品国产视频| 热久久久久久久| 亚洲国产高清aⅴ视频| 色综合视频一区二区三区高清| 亚洲在线视频网站| 精品久久国产97色综合| av一二三不卡影片| 亚洲chinese男男1069| 精品久久人人做人人爱| 91免费版在线看| 久久精品噜噜噜成人88aⅴ| 国产精品系列在线| 91精品婷婷国产综合久久性色| 国产成人在线免费观看| 亚洲午夜电影网| 久久精品视频免费观看| 欧美综合色免费| 国产成人丝袜美腿| 图片区小说区区亚洲影院| 精品国产露脸精彩对白| 在线观看欧美黄色| 国产成人午夜精品影院观看视频| 亚洲一区二区三区中文字幕| 久久午夜国产精品| 精品视频123区在线观看| 成人免费毛片高清视频| 日本视频在线一区| 伊人色综合久久天天| 久久久蜜桃精品| 欧美一区二区女人| 欧美主播一区二区三区美女| 国产精品自产自拍| 麻豆精品一二三| 亚洲图片欧美综合| 亚洲色图视频免费播放| 国产亚洲一区二区三区四区| 欧美精品 日韩| 欧美日韩精品欧美日韩精品| 成人h动漫精品一区二| 高清不卡在线观看av| 蜜臀久久99精品久久久久宅男| 亚洲精品视频在线观看免费| 中文字幕一区二区三区四区不卡| 精品欧美乱码久久久久久1区2区| 91.麻豆视频| 91 com成人网| 在线成人免费观看| 欧美日本一区二区| 欧美色大人视频| 欧美日韩精品综合在线| 91久久线看在观草草青青| 成人午夜在线播放| 成人综合在线网站| 高清国产午夜精品久久久久久| 国产成人夜色高潮福利影视| 国产在线视频精品一区| 极品少妇xxxx精品少妇偷拍| 美脚の诱脚舐め脚责91 | 欧美猛男男办公室激情| 欧洲人成人精品| 欧美日韩午夜在线视频| 欧美日韩你懂的| 欧美一级国产精品| 日韩精品中文字幕一区| 久久综合五月天婷婷伊人| 久久久综合视频| 国产精品网站在线观看| 国产精品久久久久aaaa樱花| 亚洲欧美日韩国产成人精品影院| 亚洲视频小说图片| 亚洲一区二区三区免费视频| 亚洲国产精品一区二区尤物区| 亚洲国产精品精华液网站| 日韩经典一区二区| 韩国女主播一区| 成人激情动漫在线观看| 色婷婷精品久久二区二区蜜臀av| 色婷婷综合久色| 欧美一区二区三区思思人| 久久蜜桃av一区精品变态类天堂| 欧美精彩视频一区二区三区| 亚洲视频免费在线| 日韩综合小视频| 国产黄色91视频| 欧美亚洲动漫精品| 欧美不卡一区二区| 亚洲欧洲精品一区二区三区| 午夜国产精品影院在线观看| 国内国产精品久久| 在线观看国产一区二区| 欧美一级片免费看| 中文字幕亚洲视频| 日韩电影在线一区二区| 国产精品一二三| 欧洲人成人精品| 国产亚洲欧美中文| 亚洲在线一区二区三区| 国产中文字幕精品| 欧美日韩一区二区电影| 久久免费看少妇高潮| 亚洲午夜久久久久久久久久久| 老司机精品视频一区二区三区| 99久久综合国产精品| 日韩欧美123| 亚洲国产视频a| 粗大黑人巨茎大战欧美成人| 欧美日韩一区二区在线观看| 久久久综合视频| 丝袜亚洲另类丝袜在线| 97久久精品人人做人人爽50路| 日韩欧美一区二区视频| 亚洲精品国产第一综合99久久| 国产综合久久久久影院| 久久精品人人做人人综合| 午夜欧美一区二区三区在线播放 | 亚洲国产日韩a在线播放| 国产成人综合自拍| 精品国偷自产国产一区| 亚洲一区二区成人在线观看| 成人午夜看片网址| 久久综合狠狠综合| 日韩不卡一二三区| 欧美日韩一区二区三区在线 | 日本特黄久久久高潮| 91福利国产精品| 亚洲欧洲日韩一区二区三区| 国产一区二区免费视频| 日韩欧美一区二区视频| 日本美女视频一区二区| 欧美中文字幕一区二区三区亚洲| 亚洲欧美一区二区三区极速播放 | 欧美大黄免费观看| 视频一区二区中文字幕| 欧美亚洲国产一卡| 伊人夜夜躁av伊人久久| 91性感美女视频| 亚洲精品一二三| 色8久久人人97超碰香蕉987| 亚洲精品中文在线观看| 在线视频国产一区| 一区二区三区中文字幕| 欧美日韩在线电影| 日韩av中文字幕一区二区三区| 91.麻豆视频|