Back to project page capture-the-flag.
The source code is released under:
Copyright ? 2014 Microsoft Mobile Oy. All rights reserved. Microsoft is a registered trademark of Microsoft Corporation. Nokia and HERE are trademarks and/or registered trademarks of Nokia Corporati...
If you think the Android project capture-the-flag listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * Copyright (c) 2014 Microsoft Mobile. All rights reserved. * See the license text file provided with this project for more information. *//* www. j a v a 2 s . c o m*/ package com.nokia.example.capturetheflag.network; /** * Abstract base class for network clients. */ public abstract class NetworkClient { protected enum State { IDLE, CONNECTING, CONNECTED }; protected NetworkListener mListener; protected State mState = State.IDLE; /** * Connects to the server. * * @param url The server URL. * @param port The server port. */ public abstract void connect(final String url, final int port); /** * Sets the callback listener that will be called when different kind of * messages are received. * * @param listener */ public void setListener(NetworkListener listener) { mListener = listener; } /** * Send request to the server * * @param request */ public abstract void emit(JSONRequest request); /** * Check if connection to server is open * * @return */ public abstract boolean isConnected(); /** * Disconnect from server */ public abstract void disconnect(); /** * Sets the connection idle, if the app has gone to a state where continuous * connection is not required. * * @param isIdle true for setting it idle, false for waking it up */ public abstract void setConnectionIdle(boolean isIdle); public abstract void cleanUp(); /** * Listener interface for network clients. */ public static interface NetworkListener { public void onError(JSONResponse resp); public void onUpdatePlayerMessage(UpdatePlayerResponse resp); public void onJoinedMessage(JoinedResponse resp); public void onGameListMessage(GameListResponse resp); public void onFlagCapturedMessage(FlagCapturedResponse resp); public void onNetworkStateChange(boolean isConnected, NetworkClient client); } }