亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
一本色道a无线码一区v| 懂色av一区二区在线播放| 国产精品嫩草影院com| 国产三级精品视频| 国产三级一区二区| 国产亚洲一二三区| 国产精品久久久一区麻豆最新章节| 久久久九九九九| 国产偷国产偷精品高清尤物| 国产精品黄色在线观看| 一区二区三区日韩欧美| 天天综合日日夜夜精品| 精品亚洲免费视频| av亚洲精华国产精华精华| 色偷偷久久人人79超碰人人澡| 91黄视频在线观看| 欧美一二三区在线| 国产欧美精品一区| 亚洲日本va在线观看| 一区二区三区鲁丝不卡| 蜜乳av一区二区| 成人毛片老司机大片| 欧美三级韩国三级日本三斤| 欧美一区二区三区人| 国产欧美精品一区二区三区四区| 中文字幕一区二区三中文字幕| 亚洲自拍偷拍网站| 国产永久精品大片wwwapp| 色婷婷综合久久| 欧美一区二区三级| 国产精品高潮呻吟| 美女视频一区二区| 在线观看国产日韩| 久久久不卡网国产精品二区| 亚洲一区二区在线免费看| 精品亚洲免费视频| 欧美区在线观看| 亚洲国产精品成人综合| 日日夜夜免费精品| 99麻豆久久久国产精品免费| 日韩一级精品视频在线观看| 国产精品无圣光一区二区| 日韩影院免费视频| 91香蕉视频黄| 国产三级欧美三级日产三级99 | 一本大道av一区二区在线播放| 91精品国产一区二区三区| 亚洲欧美中日韩| 久久精品久久精品| 8v天堂国产在线一区二区| 国产精品久久久久久户外露出 | 久久久综合精品| 亚洲不卡在线观看| 色妹子一区二区| 国产日韩视频一区二区三区| 久久精品国产**网站演员| 欧美午夜一区二区三区免费大片| 亚洲国产精品黑人久久久| 国产在线精品免费av| 日韩欧美国产一区二区三区| 亚洲最大色网站| 一本到一区二区三区| 国产精品伦理一区二区| 成人激情黄色小说| 国产女同性恋一区二区| 久久99精品久久久久久久久久久久| 欧美天堂亚洲电影院在线播放| 亚洲天天做日日做天天谢日日欢 | 国产乱码精品1区2区3区| 制服丝袜亚洲色图| 偷拍一区二区三区四区| 欧美日韩另类一区| 日本午夜一区二区| 日韩精品一区二区三区蜜臀 | 91福利视频久久久久| 一区二区在线观看免费| 91国产成人在线| 亚洲va欧美va国产va天堂影院| 欧美午夜电影一区| 视频一区视频二区中文| 日韩一区二区在线看| 免费成人在线影院| 亚洲精品一区二区三区影院 | 韩日欧美一区二区三区| 精品国产三级a在线观看| 国产米奇在线777精品观看| 国产欧美日韩不卡免费| 日本乱人伦aⅴ精品| 亚洲尤物视频在线| 日韩一区二区三区免费看 | 亚洲成av人片观看| 日韩欧美二区三区| 成人精品小蝌蚪| 中文字幕综合网| 欧美日韩国产一级二级| 亚洲国产日韩精品| 欧美丰满少妇xxxxx高潮对白| 美女脱光内衣内裤视频久久影院| 久久精品一区蜜桃臀影院| 99久久久精品免费观看国产蜜| 亚洲综合激情另类小说区| 日韩一区二区免费在线电影 | 亚洲视频图片小说| 在线成人av影院| 国产美女一区二区| 亚洲一区中文在线| 91精品国产综合久久久蜜臀图片| 国产a精品视频| 天天射综合影视| 欧美高清在线精品一区| 在线成人免费视频| 91在线观看视频| 精品一区二区久久久| 亚洲宅男天堂在线观看无病毒| 精品久久久久久久人人人人传媒| 91丨九色丨尤物| 久久狠狠亚洲综合| 亚洲福利一二三区| 国产精品无码永久免费888| 91精品一区二区三区在线观看| 成人精品在线视频观看| 久久精品国产亚洲aⅴ| 一区二区三区在线观看网站| 久久久噜噜噜久久中文字幕色伊伊 | 欧美日韩在线播| 国产+成+人+亚洲欧洲自线| 日韩一区精品视频| 亚洲在线中文字幕| 国产精品国产三级国产有无不卡| 精品免费国产一区二区三区四区| 欧美又粗又大又爽| 色婷婷激情一区二区三区| 国产ts人妖一区二区| 久久se精品一区二区| 午夜视频一区二区| 亚洲精品日产精品乱码不卡| 国产精品国产三级国产aⅴ中文| 日韩精品一区二区三区中文不卡| 欧美日韩亚洲综合| 91福利视频网站| 91久久久免费一区二区| 91在线播放网址| 成人精品视频一区| 91在线精品一区二区| 成人午夜视频在线| 91在线视频在线| 99久久国产综合精品麻豆 | 中文字幕一区二区三区av| 国产欧美日韩不卡免费| 久久这里只有精品6| 精品国产乱码久久久久久闺蜜| 欧美高清视频不卡网| 欧美久久一二区| 欧美日韩中字一区| 欧美挠脚心视频网站| 欧美日韩情趣电影| 欧美一区二区视频观看视频| 欧美一区二区三区公司| 欧美va在线播放| 久久综合九色综合97婷婷| 久久精品亚洲国产奇米99| 久久久久成人黄色影片| 国产欧美1区2区3区| 亚洲天堂成人在线观看| 亚洲一区欧美一区| 免费成人你懂的| 国产一区二区看久久| 国产福利91精品一区二区三区| 成人手机电影网| 91免费看视频| 欧美年轻男男videosbes| 欧美不卡激情三级在线观看| 久久久久久久免费视频了| 国产欧美一区二区三区沐欲 | 中文字幕+乱码+中文字幕一区| 中文字幕免费一区| 亚洲欧美日韩国产综合| 亚洲成年人网站在线观看| 免费成人av资源网| 成人av在线电影| 欧美日韩国产乱码电影| 久久久影视传媒| 亚洲欧美一区二区三区久本道91| 午夜不卡av在线| 成人性生交大片免费看中文网站| 成人avav影音| 欧美日韩成人一区| 中文字幕欧美日本乱码一线二线| 一区二区三区自拍| 国产一区二区精品久久99| 色综合天天综合| 91精品国产综合久久精品app| 日本一区二区三区四区| 亚洲va天堂va国产va久| 成人午夜大片免费观看| 91精品国产一区二区人妖| 中文字幕中文在线不卡住| 奇米精品一区二区三区四区| 成人天堂资源www在线| 9191久久久久久久久久久|