view test/channeltest/testEditor.java @ 382:4b87f89b3afd

REP Session Manager (Java version) new structure
author one@firefly.cr.ie.u-ryukyu.ac.jp
date Mon, 10 Nov 2008 22:07:45 +0900
parents 1eec69035548
children
line wrap: on
line source

package test.channeltest;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;

import rep.channel.REPLogger;
import rep.channel.REPSocketChannel;


public class testEditor extends Thread{
	private SocketAddress semaIP;
	private REPLogger ns;
	
	public testEditor(String name, String _host,int _port){
		super(name);
		semaIP = new InetSocketAddress(_host, _port);
		ns = REPLogger.singleton();
	}

	public void run(){
		try {
			REPSocketChannel<String> channel;
			channel = REPSocketChannel.<String>create(new StringPacker());
			channel.configureBlocking(true);

			ns.writeLog("try to connect to SessionManager whose ip is "+semaIP, 1);
			while (!channel.connect(semaIP)){
				ns.writeLog("SeMa not listen to socket yet, wait", 1);
				Thread.yield();
			}
			ns.writeLog("successes to connect", 1);

			channel.write(getName()+": send hello");
			ns.writeLog("wrote packet", 1);

			String packet = channel.read();

			ns.writeLog("gets return string==> `"+packet+"\'", 1);

			ns.writeLog("testEditor exits.", 1);
		} catch (IOException e) {
		}
	}
}