synchronized protected void negotiate() throws IOException
	{
		if(this.input != null)
			try { this.input.close(); }  catch(IOException f)  { }
		
		if(this.output != null)
			try { this.output.close(); }  catch(IOException f)  { }
		
		if(this.socket != null)
			try { this.socket.close(); }  catch(IOException f)  { }
		
		this.socket = new Socket(host, port);
		this.socket.setTcpNoDelay(true);
		this.socket.setKeepAlive(true);

		this.input = new DataInputStream(socket.getInputStream());
		this.output = new DataOutputStream(socket.getOutputStream());

		long thisBlockCount = NBDUtil.readHello(input, writableExpected);
		if(this.blockCount != null)
		{
			if((long)this.blockCount != thisBlockCount)
				throw new RuntimeException(String.format("device size changed during renegotiation!  Was %d, now %d", this.blockCount, thisBlockCount));
		}
		else
		{
			this.blockCount = thisBlockCount;
		}
	}