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

📄 main.java

📁 利用mina框架写的一个通信实例。初学者的一个好教程。
💻 JAVA
字号:
/*
 * @(#) $Id: Main.java 357871 2005-12-20 01:56:40Z trustin $
 */
package org.apache.mina.examples.tennis;

import org.apache.mina.common.TransportType;
import org.apache.mina.protocol.ProtocolSession;
import org.apache.mina.protocol.vmpipe.VmPipeAddress;
import org.apache.mina.protocol.vmpipe.VmPipeConnector;
import org.apache.mina.registry.Service;
import org.apache.mina.registry.ServiceRegistry;
import org.apache.mina.registry.SimpleServiceRegistry;

/**
 * (<b>Entry point</b>) An 'in-VM pipe' example which simulates a tennis game
 * between client and server.
 * <ol>
 * <li>Client connects to server</li>
 * <li>At first, client sends {@link TennisBall} with TTL value '10'.</li>
 * <li>Received side (either server or client) decreases the TTL value of the
 * received ball, and returns it to remote peer.</li>
 * <li>Who gets the ball with 0 TTL loses.</li>
 * </ol>
 * 
 * @author The Apache Directory Project (dev@directory.apache.org)
 * @version $Rev: 357871 $, $Date: 2005-12-20 10:56:40 +0900 (Tue, 20 Dec 2005) $
 */
public class Main {

	public static void main(String[] args) throws Exception {
		ServiceRegistry registry = new SimpleServiceRegistry();

		VmPipeAddress address = new VmPipeAddress(8080);

		// Set up server
		Service service = new Service("tennis", TransportType.VM_PIPE, address);
		registry.bind(service, new TennisPlayer());

		// Connect to the server.
		VmPipeConnector connector = new VmPipeConnector();
		ProtocolSession session = connector
				.connect(address, new TennisPlayer());

		// Send the first ping message
		session.write(new TennisBall(10));

		// Wait until the match ends.
		while (session.isConnected()) {
			Thread.sleep(100);
		}

		registry.unbind(service);
	}
}

⌨️ 快捷键说明

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