void ServerConnectionAdapter::flush() {
	try {
		connection.flush();
	} catch (IOException& e) {
		ioException(e);
	}
}
void ServerConnectionAdapter::ensureAlive() {
	try {
		connection.sendKeepAlive();
	} catch (IOException& e) {
		ioException(e);
	}
}
void ServerConnectionAdapter::offerOutgoingUpdate(NetworkTableEntry* entry) {
	try {
		if(connectionState==&ServerConnectionState::CONNECTED_TO_CLIENT)
			connection.sendEntryUpdate(*entry);
	} catch (IOException& e) {
		ioException(e);
	}
}
void ClientConnectionAdapter::offerOutgoingUpdate(NetworkTableEntry* entry) {
	try {
		{
			Synchronized sync(LOCK);
			if(connection!=NULL && connectionState==&ClientConnectionState::IN_SYNC_WITH_SERVER)
				connection->sendEntryUpdate(*entry);
		}
	} catch(IOException& e){
		ioException(e);
	}
}
void ClientConnectionAdapter::flush() {
	{
		Synchronized sync(LOCK);
		if(connection!=NULL) {
			try {
				connection->flush();
			} catch (IOException& e) {
				ioException(e);
			}
		}
	}
}
void ClientConnectionAdapter::serverHelloComplete() {
	if (connectionState==&ClientConnectionState::CONNECTED_TO_SERVER) {
		try {
			gotoState(&ClientConnectionState::IN_SYNC_WITH_SERVER);
			entryStore.sendUnknownEntries(*connection);
		} catch (IOException& e) {
			ioException(e);
		}
	}
	else
		throw BadMessageException("A client should only receive a server hello complete once and only after it has connected to the server");
}
void ClientConnectionAdapter::ensureAlive() {
	{
		Synchronized sync(LOCK);
		if(connection!=NULL) {
			try {
			  connection->sendKeepAlive();
			} catch (IOException& e) {
				ioException(e);
			}
		}
		else
			reconnect();//try to reconnect if not connected
	}
}