view src/main/java/jp/ac/u_ryukyu/treevnc/client/MyRfbProtoClient.java @ 143:4547543ca73c

findRootReply
author oc
date Thu, 12 Jun 2014 19:21:38 +0900
parents ada4d850a820
children 1e004d9c599d
line wrap: on
line source

package jp.ac.u_ryukyu.treevnc.client;

import java.io.IOException;
import java.io.OutputStream;

import jp.ac.u_ryukyu.treevnc.MyRfbProto;

import com.glavsoft.exceptions.TransportException;
import com.glavsoft.rfb.protocol.ProtocolContext;
import com.glavsoft.transport.Reader;

public class MyRfbProtoClient extends MyRfbProto {
	private Reader reader;
	private ProtocolContext context;
	boolean proxyFlag = false;
	int serverMajor, serverMinor;
	int clientMajor, clientMinor;
	private boolean normalTermination;
	private TreeVncRootSelectionPanel rootSelectionPanel;


	public MyRfbProtoClient() {

	}

	public MyRfbProtoClient(Reader reader, String host, String port) {
		this.reader = reader;
	}

    @Override
    public boolean isRoot() {
        return false;
    }
    
	public boolean readProxyFlag() throws TransportException {
		int flag = reader.readUInt8();
		if (flag == 1)
			return true;
		else
			return false;
	}


	void sendInitData(OutputStream os) throws IOException {
		os.write(context.getInitData());
	}

	
	@Override
	public void setTerminationType(boolean setType) {
		normalTermination = setType;
	}
	
	@Override
	public boolean getTerminationType() {
		return normalTermination;
	}
	
	
	public void addHostToSelectionPanel(int port, String hostname) {
		if (rootSelectionPanel != null) {
			rootSelectionPanel.checkBox(Integer.toString(port) + ":" + hostname);
			rootSelectionPanel.setButton();
			rootSelectionPanel.visible();			
		}
	}
	
	@Override
	public void createRootSelectionPanel() {
		rootSelectionPanel = new TreeVncRootSelectionPanel();
	}
	
	
	/* 
	 * measure client delay time using tree connection. It should be summed up in upward tree communication 
	 */
	@Override
	public void readCheckDelay(Reader reader) throws TransportException {
//		ByteBuffer buf = multicastqueue.allocate(24);
//		reader.readBytes(buf.array(), 0, 24);
//		
//		LinkedList<ByteBuffer> sendData = new LinkedList<ByteBuffer>();
//		sendData.add(buf);
//		Socket echoSocket;
//		try {
//			echoSocket = new Socket(getProxyAddr(), 10002);
//			BufferedReader is = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));
//			DataOutputStream os = new DataOutputStream(echoSocket.getOutputStream());
//			os.writeBytes("checkdelay\n");
//			os.writeBytes(String.valueOf(buf.getLong(16))+"\n");
//			System.out.println("delay"+ is.readLine());
//		} catch (UnknownHostException e) {
//			e.printStackTrace();
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//		buf.position(0);
//		
//		multicastqueue.put(sendData);
		
	}
}